Calling shared libs from static libs

Russell Shaw rjshaw@iprimus.com.au
Wed Oct 1 14:31:00 GMT 2003


Michael Matz wrote:
> Hi,
> 
> On Wed, 1 Oct 2003, Russell Shaw wrote:
> 
> 
>>ld  -o shapegen -static /usr/lib/gcrt1.o main.o gui.o xmalloc.o object.o menu.o dialog.o
>>     -L /usr/X11R6/lib
>>     -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0
>>     -lpangox-1.0 -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0
>>     -lc /usr/lib/gcc-lib/i386-linux/3.3.1/libgcc.a
> 
> You of course have to link against the necessary libraries.  -lX11 to
> start with.

Thanks. I got it to compile as a mixture of static and dynamic:

gcc -g -O0 -o shapegen main.o gui.o xmalloc.o object.o menu.o dialog.o
     -Wl,/usr/lib/libgtk-x11-2.0.a /usr/lib/libgdk-x11-2.0.a -latk-1.0
     -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0 -lpango-1.0
     -lgmodule-2.0 -ldl /usr/lib/libglib-2.0.a /usr/lib/libgobject-2.0.a
     -L /usr/X11R6/lib -lXinerama -lXi
     -lc

It seems that static .a libraries can only be found by using the explicit
path if you are linking a mixture of static and dynamic libraries, because
specifying -static anywhere in the linker options seems to make *everything*
static even if you have -Bdynamic for some libraries (gcc 3.3.1, ld 2.14.90.0.4).

Is this a bug, or should -static apply globally?



More information about the Binutils mailing list