Boost logo

Boost-Build :

Subject: [Boost-build] Dependency on shared library from static library (mixing shared and static libs)
From: Johan Nilsson (r.johan.nilsson_at_[hidden])
Date: 2009-02-03 08:21:53


consider the following:

- Library "a" that can be built for shared or static linking.
- Library "b" depends on "a", but can only be built for static linking.
- App "c" depends (directly) on "b".

All the above are defined as Boost.Build targets within a single project.

I would like to be able to:

1. Build app "c" to use the shared version of "a" (e.g. bjam link=shared):
    - Link statically to "b" (as this is the only possibility)
    - Link shared to "a"
    - Lib "b" should reference the shared build of "a"

2. Build app "c" to use the static version of "a" (e.g. bjam link=static):
    - Link statically to "b"
    - Link statically to "a"
    - Lib "b" should reference the static build of "a"

Please see attached zipfile or the extracts below for a non-working
example - if I run "bjam link=shared" the app "c" is statically linked to
both "a" and "b" - presumably because the <link>static for lib "b" is
propagated to lib "a" as well.

Any ideas on how to work around this problem? I've tried fiddling around
with the requirements for the different targets to no avail.

I've been using Boost.Build/Boost.Jam from Boost 1.34.1 as well as from the
trunk, using the msvc-8.0 toolset.

Regards / Johan

--- a.h ---
#if defined (A_BUILD_DLL)
# define A_DECL __declspec(dllexport)
#elif defined (A_USE_DLL)
# define A_DECL __declspec(dllimport)
# define A_DECL

int A_DECL a();

--- a.cpp ---
#include "a.h"

int a()
 return 0;

--- b.h ---
int b();

--- b.cpp ---
#include "b.h"
#include "a.h"

int b()
 return a();

--- c.cpp ---
#include "b.h"

int main(int , char* [])
 return b();

--- Jamroot ---
project foo ;

# can be built as static or shared library
lib a
  : a.cpp
  : <link>shared:<define>A_BUILD_DLL
  : <link>shared:<define>A_USE_DLL

# can only be built as static library
lib b : b.cpp : <link>static <library>a ;

exe c : c.cpp : <library>b ;

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