Boost logo

Boost-Build :

Subject: Re: [Boost-build] Dependency on shared library from static library (mixing shared and static libs)
From: Alexander Sack (pisymbol_at_[hidden])
Date: 2009-02-03 10:56:07

On Tue, Feb 3, 2009 at 8:21 AM, Johan Nilsson <r.johan.nilsson_at_[hidden]> wrote:
> Hi,
> 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"

Well I believe static libb can't be linked with shared a. That
doesn't make sense to me. See here for more linkage info with respect
to Boost.Build:

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

This is what I did with your Jamroot and got results which I *think*
are what you want:

project foo ;

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

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

exe c : c.cpp b a ;

I was able to produce an executable c which was either statically
linked with both liba and libb or dependent on just liba:

# ldd bin/gcc-3.4.4/debug/c
bin/gcc-3.4.4/debug/c: => /root/shared_static_libs/bin/gcc-3.4.4/debug/ (0x80062a000) => /usr/lib/ (0x80072b000) => /lib/ (0x800922000) => /lib/ (0x800a3e000)
# ldd bin/gcc-3.4.4/debug/link-static/c
bin/gcc-3.4.4/debug/link-static/c: => /usr/lib/ (0x80062a000) => /lib/ (0x800821000) => /lib/ (0x80093d000)


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