Boost logo

Boost :

From: Caleb Epstein (caleb.epstein_at_[hidden])
Date: 2005-03-22 11:11:33


On Tue, 22 Mar 2005 13:02:38 -0000, John Maddock <john_at_[hidden]> wrote:
> > Who should I work with to get the appropriate tests marked as
> > known-to-fail or N/A? This exercise is necessary for some
> > gcc-on-Solaris tests as well. For instance, all of the "*_lib" tests
> > in Boost.Thread fail because "gcc -static" won't link with *any*
> > shared libs. Solaris does not provide static versions of -lrt or
> > -lthread, so these tests fail to link. There really should really be
> > a "-prefer-static" option to gcc.. Alternately, the Jamfiles could be
> > hacked to use -Wl,-Bstatic / -Wl,-Bdynamic guards around the inclusion
> > of the Boost.Thread lib for these tests.
>
> That would probably be my preferred option, is it just a case of
> adding -Wl,-Bdynamic to the very end of the command line? Rene would
> probably know the best way to fix this.

In my testing, I have found that you can't use "gcc -static" on
Solaris if you have *any* shared libs to link with. It overrides even
later uses of -Wl,-Bdynamic (in fact using both -static and
-Wl,-Bdynamic causes a linker error - see below).

If you want to link with static versions of some libs and dynamic
versions of others (as one must in the case of the Boost.Thread tests
which use -lpthread and -lrt for which no static versions exist), it
appears that the only way to do this is to specify the static libs as
fully qualified filenames (e.g. /path/to/libfoo.a). See the examples
below:

static.c:

---
#include <curses.h>
int main () { initscr (); endwin (); return 0; }
---
Link statically with -lcurses (OK)
% gcc -static -o static static.c -lcurses
Try to link statically with -lcurses and -lrt (fails - no librt.a exists)
% gcc -static -o static static.c -lcurses -lrt
ld: fatal: library -lrt: not found
ld: fatal: File processing errors. No output written to static
collect2: ld returned 1 exit status
Try to link statically with -lcurses and dynamically with -lrt (fails
- linker error)
% gcc -static -o static static.c -lcurses -Wl,-Bdynamic -lrt
ld: fatal: option -dn and -Bdynamic are incompatible
ld: fatal: library -lrt: not found
ld: fatal: File processing errors. No output written to static
collect2: ld returned 1 exit status
Try to link statically with -lcurses only (OK):
% gcc -o static static.c -Wl,-Bstatic -lcurses -Wl,-Bdynamic -lrt
% ldd static
        librt.so.1 =>    /usr/lib/librt.so.1
        libc.so.1 =>     /usr/lib/libc.so.1
        libaio.so.1 =>   /usr/lib/libaio.so.1
        libdl.so.1 =>    /usr/lib/libdl.so.1
        /usr/platform/SUNW,Netra-T12/lib/libc_psr.so.1
Also, note that -Wl,-Bdynamic must be in effect at the end of the
command line because gcc does not provide a static version of -lgcc_s.
 Not sure why this happens, though, because -static works for this
case:
hello.cpp:
#include <iostream>
int main () { std::cout << "Hello World!\n"; return 0; }
% g++ -o hello hello.cpp -Wl,-Bstatic
ld: fatal: library -lgcc_s: not found
ld: fatal: library -lgcc_s: not found
ld: fatal: File processing errors. No output written to hello
collect2: ld returned 1 exit status
% g++ -o hello hello.cpp -Wl,-Bstatic -Wl,-Bdynamic
% ./hello
Hello World!
% g++ -static -o hello hello.cpp
% ./hello
Hello World!
Not sure what the difference is between the -Wl,-Bstatic and -static
cases is here.
-- 
Caleb Epstein
caleb dot epstein at gmail dot com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk