|
Boost-Build : |
Subject: Re: [Boost-build] Dependency on shared library from staticlibrary(mixing shared and static libs)
From: Johan Nilsson (r.johan.nilsson_at_[hidden])
Date: 2009-02-04 09:35:28
"Alexander Sack" <pisymbol_at_[hidden]> skrev i meddelandet
news:3c0b01820902031031v2cb9bd5bh1429562011033c4a_at_mail.gmail.com...
> On Tue, Feb 3, 2009 at 12:30 PM, Johan Nilsson
> <r.johan.nilsson_at_[hidden]> wrote:
>> Alexander Sack wrote:
>>>
>>> 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.
>>
>> Well, obviously a static lib can't be linked (at least not with msvc).
>> Hence
>> the "... _reference_ the shared build of a" (which could be even more
>> specific by stating "contains references to the functions exported by the
>> shared build of a", perhaps).
>>
>>> That
>>> doesn't make sense to me. See here for more linkage info with respect
>>> to Boost.Build:
>>>
>>> http://www.boost.org/doc/tools/build/doc/html/bbv2/tutorial/linkage.html
>>>
>>>> 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"
>>>
[snip]
>
> Do you still have the issue though?
Yes. Your suggested solution generates both shared and static versions of
"a", and passes both as linker inputs for msvc. See below for relevant part
of output using "bjam -d+2"
----------
file bin\msvc-8.0\debug\threading-multi\c.exe.rsp
"bin\msvc-8.0\debug\threading-multi\a.lib"
"bin\msvc-8.0\debug\link-static\threading-multi\libb.lib"
"bin\msvc-8.0\debug\threading-multi\c.obj"
"bin\msvc-8.0\debug\link-static\threading-multi\liba.lib"
msvc.link bin\msvc-8.0\debug\threading-multi\c.exe
call "C:\dev\ide\vs8\VC\vcvarsall.bat" x86 >nul
link /NOLOGO /INCREMENTAL:NO /DEBUG /subsystem:console
/out:"bin\msvc-8.0\debug\threading-multi\c.exe"
@"bin\msvc-8.0\debug\threading-multi\c.exe.rsp"
if %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL%
if exist "bin\msvc-8.0\debug\threading-multi\c.exe.manifest" (
mt -nologo -manifest
"bin\msvc-8.0\debug\threading-multi\c.exe.manifest"
"-outputresource:bin\msvc-8.0\debug\threading-multi\c.exe;1"
)
----------
I can achieve the required mix of shared/static libraries if adding the
<link>shared requirement to lib a, as follows:
--- Jamroot ---
project foo ;
# can now be only be built as shared library
lib a
: a.cpp
: <link>shared:<define>A_BUILD_DLL <link>shared
:
: <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 ;
----------
This gives the following output (compare to above):
---------------
file bin\msvc-8.0\debug\threading-multi\c.exe.rsp
"bin\msvc-8.0\debug\threading-multi\c.obj"
"bin\msvc-8.0\debug\threading-multi\a.lib"
"bin\msvc-8.0\debug\link-static\threading-multi\libb.lib"
msvc.link bin\msvc-8.0\debug\threading-multi\c.exe
call "C:\dev\ide\vs8\VC\vcvarsall.bat" x86 >nul
link /NOLOGO /INCREMENTAL:NO /DEBUG /subsystem:console
/out:"bin\msvc-8.0\debug\threading-multi\c.exe"
@"bin\msvc-8.0\debug\threading-multi\c.exe.rsp"
if %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL%
if exist "bin\msvc-8.0\debug\threading-multi\c.exe.manifest" (
mt -nologo -manifest
"bin\msvc-8.0\debug\threading-multi\c.exe.manifest"
"-outputresource:bin\msvc-8.0\debug\threading-multi\c.exe;1"
)
------------
But (big but): I would like to be able to switch between shared and static
builds of lib "a" without modifying the Jamfile(s).
Ideally, invoking "bjam link=shared" using the original Jamroot would give
the above result, while "bjam link=static" would use both a and b as static
libraries.
Anyone?
/ Johan
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