[gambit-list] static lib question

REPLeffect repleffect at gmail.com
Fri Feb 3 03:50:04 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
>

 I finally tried actually building the contents of the tar file (silly
me, I should have done that right away).

Here are the results I got:

$ make
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
f1.a(f1a.o): In function `___H__20_f1a(___processor_state_struct*)':
f1a.c:(.text+0x126): undefined reference to `f1b_hello()'
f2.a(f2a.o): In function `___H__20_f2a(___processor_state_struct*)':
f2a.c:(.text+0x126): undefined reference to `f2b_hello()'
collect2: ld returned 1 exit status
*** ERROR IN ##main -- C link failed while linking "f3_.o" "f3.o"
make: *** [f3.exe] Error 70

I suspected this was due to the fact that I am using Gambit 4.6.3
compiled with --enable-cplusplus.
Sure enough, I compiled another copy without the -enable-cplusplus
option, and the code above
compiles fine on it.

Then I finally woke up from my stupor, and changed the call to "gcc"
on line 7 of
the makefile to "g++".

Sometimes I wonder what exotic places my brain visits when it is "on
vacation", and
if it had a good time while it was there.  :-D



More information about the Gambit-list mailing list