This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Calling shared libs from static libs


Russell Shaw wrote:
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?

I think i found the problem. I assumed that anything starting with "-" after -Wl was passed to the linker. However, i think everything needs commas. This works now:

gcc -g -O0 -o shapegen main.o gui.o xmalloc.o object.o menu.o dialog.o
    -Wl,-Bstatic,
    -lgtk-x11-2.0,-lgdk-x11-2.0,-latk-1.0,-lgdk_pixbuf-2.0,-ltiff,-lpng,
    -lpangoxft-1.0,-lpangox-1.0,-lpango-1.0,-lgmodule-2.0,-lgobject-2.0,
    -lglib-2.0,
    -Bdynamic,-lfreetype,-lfontconfig,-ljpeg,-ldl,
    -L/usr/X11R6/lib,-lXinerama,-lXi,-lXft,-lm,-lc


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]