Boost logo

Boost-Build :

Subject: [Boost-build] Linking static library against shared library
From: Anthony Foglia (AFoglia_at_[hidden])
Date: 2010-05-13 17:21:08


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
    ;

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.

The only solution seems to be to change lib utilities to

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

This seems contrary to the idea of defining usage requirements with the
target that requires them. Is there some jam voodoo that I'm missing?

-- 
Anthony Foglia
Princeton Consultants
(609) 987-8787 x233

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