Boost logo

Boost-Build :

Subject: Re: [Boost-build] Linking static library against shared library
From: Gevorg Voskanyan (v_gevorg_at_[hidden])
Date: 2010-05-14 03:24:55


Anthony Foglia wrote:
> We're trying to build our custom libraries statically, but they use librt, which
> (on Ubuntu Intrepid) apparently needs to be linked dynamically. Our jam
> file for the library looks like:

> lib utilities
> : [ glob src/*.cpp ]
> /sysdefs//boost-program-options
> /sysdefs//boost-filesystem
> /sysdefs//lib-real-time
> : <include>./include
> <link>static
> :
> : <include>./include
> <link>static
> ;

Do you really want to force other libraries that happen to use lib utilities to become statically linked?

> And librt is defined as lib-real-time in a file sysdefs.jam with the following lines:
>
> lib lib-real-time #FOR: librt (implicit for threading)
> :
> : <threading>single <name>rt
> ;
>
> alias lib-real-time : : ;
>
> Compiling a simple test program, this links librt statically,
> which fails (undefined reference to `_dl_cpuclock_offset').
>
> Now I would think the correct change would be to change the first lib-real-time definition to reflect that librt
> must be linked dynamically, like so
>
> lib lib-real-time #FOR: librt (implicit for threading)
> :
> : <threading>single <name>rt : : <link>shared
> ;
>
> But this causes libutilites to be linked to dynamically (libutilities.so is created).
> Despite using <link>static in the requirements and the usage requirements of utilities,
> for some reason bjam is ignoring them and still wants to build utilities shared.

This is because you specified <link>shared in the usage requirements section of lib-real-time, so it becomes a requirement for libutilities which uses lib-real-time. Just move it to the requirements section like this:

lib lib-real-time #FOR: librt (implicit for threading)
  :
  : <threading>single <name>rt <link>shared
  ;

Also I think you can get away with just one alternative of lib-real-time if it is defined as

lib lib-real-time
  :
  : <link>shared <threading>single:<name>rt
  ;

and then "alias lib-real-time : : ;" would no longer be needed.

HTH,
Gevorg


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk