Boost logo

Boost-Build :

From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2007-09-01 10:08:23

The problem:

It is possible to specify searchable libraries in bb via the <name> tag:

lib foo : <name>foo ;

and later use it:

exe main : foo ;

It is also possible to request the library linked in statically:

exe main : foo/<link>static ;

However this does not work (reliably). It depends which library versions
are in the search path. If both versions are present (libfoo.a and always the shared gets preference.

This behaviour deemed unsatisfying to me.

The analysis:

bb, while cleanly separating searches for static and dynamic libraries
until the call to the linker: -l$(FINDLIBS-ST) -l$(FINDLIBS-SA), it does
not currently make use of appropriate linker switches.

The respective linker switches are -Bstatic and -Bdynamic.

My first attempt was, to change the linker call appropriately:

-Wl,-Bstatic -l$(FINDLIBS-ST) -Wl,-Bdynamic -l$(FINDLIBS-SA)

This worked fine on linux, but failed on windows (mingw) where it always
picked up the static library.

So I digged deeper (into the sources of ld), and this is what I found:

The -Bstatic and -Bdynamic switches simply change the search order for
filenames of -l switches that follow them.

On Linux (ELF Format) ld searches for:

-Bstatic -lxxx :

-Bdynamic -lxxx :

On mingw (PE Format) ld searches for:

-Bstatic -lxxx :

-Bdynamic -lxxx :

Now the problem becomes understandable:
Since bb's default naming of libraries on windows is:

Static lib: libxxx.a
Shared lib: xxx.dll and xxx.a for the import lib.

it can be seen from the tables above this naming convention leads
inevitable to the described behavior.

The (proposed) solution:

1) Change naming on windows to
     Static libs: libxxx.lib
     DLL's : xxx.dll
     Import libs: xxx.lib
   This naming is also more in line with the other windows

2) Add the -Bstatic and -Bdynamic switches to the linker line.

3) Add a additional lib prefix to searched (static) libs when on

Point 3) needs a little further explanation:
The additional prefix "lib" will result in a linker cmd: -llibxxx
 From the above tables one can easily see that this will pull in the
correct static library. The wary reader will have noticed, that this
will work whether the -Bstatic switch is present or not. This is
correct. But the switches are needed on linux.

Instead of the proposed naming scheme also a different one could be used:
   Static libs: libxxx.a
   DLL's : xxx.dll
   Import libs: xxx.dll.a

In this case of course one must not prefix "lib" to the -l, and the
-Bstatic and -Bdynamic are required.

I appologize for the lenght of this post, but I hope this will lead to
an improvement of bb. I would be very interested of your opinion before
changing bb.

Roland aka speedsnail

Boost-Build list run by bdawes at, david.abrahams at, gregod at, cpdaniel at, john at