Boost logo

Boost-Build :

Subject: Re: [Boost-build] Dependency on shared library from static library (mixing shared and static libs)
From: Vladimir Prus (ghost_at_[hidden])
Date: 2009-02-06 05:01:01


On Tuesday 03 February 2009 16:21:53 Johan Nilsson wrote:

> 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.

This is not possible. As soon as 'b' gets <link>static via requirements,
it will propagate that property to all dependencies, and there's no way to
stop that. Maybe, we need a special syntax to indicate either:

        - <link>static is for this target only, don't propagate it further, e.g:

                        lib b : b.cpp : *<link>static ;

        - When building a dependency, we need not use target's requirements, e.g.:

                        lib b : b.cpp a/<link>* : <link>static ;

        will cause 'a' to be built with whatever properties 'b' was requested (say,
        on command line) -- ignoring <link>static.

I'm not sure which approach is best -- do you have an opinion?

- Volodya

>
> 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)
> #else
> # define A_DECL
> #endif
>
> 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 acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk