Subject: Re: [Boost-build] linking a library from static libraries
From: Vladimir Prus (ghost_at_[hidden])
Date: 2009-06-04 02:17:05
On Thursday 04 June 2009 09:21:02 Paul Fox wrote:
> I am working on the build system for a fairly large project, which will
> produce a static and a shared-object version of a library. In order to keep
> the project manageable, it has been divided into several modules.
> Each module is currently building as a static library, and the Jamroot for
> the project lists all of the applicable sub-projects as dependencies.
> However, I found that it was in fact building an empty library, both in
> static and dynamic mode!
> Doing some poking around, I discovered that for the static build, it was not
> passing ar the static libraries at all, instead only giving it one system
> shared library to link against. I also discovered that in dynamic mode, it
> was giving ld the appropriate list of libraries, but ld was ignoring them.
> Upon further investigation, I discovered that neither ar nor ld will accept
> static (.a) libraries as arguments to build a library by default. ar expects
> object files, which would require the relevant .a files to be unpacked, and
> ld will only include .a files in a dynamic library if you use the
> --whole-archive flag preceding the list, and the --no-whole-archive flag
> following it.
> I therefore currently have to execute the last linking step manually after
> boost-build executes, which is far from ideal. What would be the best way to
> handle this in boost-build? Is there another way I can type the modules so
> that they will return a bunch of object files instead of a library? Is there
> a way to make boost-build aware of how to create a library from a library?
Given that the underlying tools don't really allow this, I don't think
much can be done on Boost.Build side.
> What is the cleanest solution?
The simplest solution might be this:
alias the_submodule : a.cpp b.cpp ;
lib all : submodule//the_submodule ;
However, this approach does not make it possible to use different
compiler options for different submodules. If that is desired,
1. Put the attached convert.jam to 'tools' dir of boost.build.
2. In your Jamroot, add:
import convert ;
3. In your submodule/Jamfile, use:
convert submodule obj : a.cpp b.cpp ;
4. In you Jamroot, just use the 'submodule' target as you would
use a library.
You can also grab SVN HEAD version of Boost.Build -- in which cases
steps (1) and (2) are not necessary.
Let me know if this helps.
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