RE: Linking dynamic a static libraries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Actually, you may want to put the static libraries last and then end
your command line with a final -Wl,-Bdynamic:

gcc -o myexecutable \
-v \
*.c \
-Wl,-Bdynamic \
-lfirst \
-lsecond \
-Wl,-Bstatic \
-lthird \
-Wl,-Bdynamic

This is because if your dynamic libraries depend on symbols from your
static libraries, they might not get picked up if you put the static
libraries first.  The final -Wl,-Bdynamic will allow it to link in the
standard libraries normally.

Thanks,
Lyle


-----Original Message-----
From: gcc-help-owner@xxxxxxxxxxx [mailto:gcc-help-owner@xxxxxxxxxxx] On
Behalf Of Eljay Love-Jensen
Sent: Thursday, January 13, 2005 5:31 AM
To: Roman Pagac; gcc-help@xxxxxxxxxxx
Subject: Re: Linking dynamic a static libraries

Hi Roman,

With GCC, you should be able to do something like this:

gcc -o myexecutable \
-v \
*.c \
-Wl,-Bstatic \
-lfirst \
-lsecond \
-Wl,-Bdynamic \
-lthird

The compiler will link to libfirst.a and libsecond.a (both static), and 
libthird.so and the support libraries (dynamic).

The -v will display the magic-behind-the-curtains, and you'll see that
the 
linker step is adding in (your mileage may vary) ...
crt0.o, crtbegin.o, and crtend.o
some compiler specific or system library paths
-lstdc++
-lgcc
-lcygwin
-luser32
-lkernel32
-ladvapi32
-lshell32
-lgcc

You'll also see where the -Bstatic and -Bdynamic are affecting library
linkage.

HTH,
--Eljay





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux