[gambit-list] static lib question

REPLeffect repleffect at gmail.com
Thu Feb 2 12:45:38 EST 2012


On Thu, Feb 2, 2012 at 11:03 AM, Marc Feeley <feeley at iro.umontreal.ca> wrote:
>
> On 2012-02-02, at 10:45 AM, REPLeffect wrote:
>
>> Let's say I have the following set of files ...
>>
>>  f1a.scm and f1b.c
>>
>>  f2a.scm and f2b.c
>>
>>  f3.scm
>>
>>  File f1a.scm contains scheme procedures that call C functions in f1b.c.
>>
>>  File f2a.scm contains scheme procedures that call C funcitons in f2b.c.
>>
>>  I would like to build a static library f1.a from f1a.scm and f1b.c,
>>
>> and likewise I wish to build a static library f2.a from f2a.scm and f2b.c.
>>
>> Finally, assume f3.scm will call scheme procedures from both the f1.a and
>> f2.a static libraries.
>>
>> What are the appropriate commands for:
>>
>> 1) building the f1.a and f2.a static libraries
>>
>> 2) compiling and linking f3.scm with *both* of those static libraries
>> at the same time.
>>
>> (I'm looking for an example using gcc on a Linux platform.)
>
> Here are the steps.  The gist is that you have to create flat link files for each library, and then create an incremental link file for the final executable from the library link files.
>
> gsc -c -o f1a.c f1a.scm
> gsc -obj -o f1a.o f1a.c
> gcc -c -o f1b.o f1b.c
> gsc -link -flat -o f1_.c f1a.c f1b.c
> *** WARNING -- "display" is not defined,
> ***            referenced in: ("f1a.c")
> gsc -obj -o f1_.o -cc-options "-D___LIBRARY" f1_.c
> ar -rc f1.a f1a.o f1b.o f1_.o
> gsc -c -o f2a.c f2a.scm
> gsc -obj -o f2a.o f2a.c
> gcc -c -o f2b.o f2b.c
> gsc -link -flat -o f2_.c f2a.c f2b.c
> *** WARNING -- "display" is not defined,
> ***            referenced in: ("f2a.c")
> gsc -obj -o f2_.o -cc-options "-D___LIBRARY" f2_.c
> ar -rc f2.a f2a.o f2b.o f2_.o
> gsc -c -o f3.c f3.scm
> gsc -obj -o f3.o f3.c
> gsc -link -o f3_.c f1_.c f2_.c f3.c
> gsc -obj -o f3_.o f3_.c
> gsc -exe -o f3.exe -ld-options "f1.a f2.a" f3_.o f3.o
>
> I have included a tar file which contains an example with makefile.  It has been tested on Linux and Mac OS X.
>
> Marc
>

OK, now I don't feel quite so stupid for not being able to figure it
out on my own :-D

I was pretty sure the link files were my problem, but I wasn't sure
how to get from point A to point B.  Unless I'm just blind (which is
always a possibility) there aren't any examples in the manual of
creating a static library, and I didn't have any luck finding what I
was looking for in the mailing list archive.

Thanks again for the superb and timely help, Marc!



More information about the Gambit-list mailing list