Boost logo

Boost-Build :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-08-31 08:47:17


Hi Toon,
> First of all: thanks for the great bjamv2 system. In two weeks I managed
> to convert 5 projects with a total of 100K lines to the bjamv2 build
> system on multiple platforms. There are still some quirks but most of it
> is operational.

Great.

> One of those quirks however is very interesting: I have an exe which
> contains an embedded python interpreter. Next I also build python
> extensions modules with bjam. When I 'import' these extensions into
> python, these dynamic libraries need to find symbols defined into the
> executable. This can be done using the --export-dynamic flag when using
> the gnu linker. But of course, when I link my application, it does not
> know yet that some symbols will be used later on by libraries that are
> dynamically linked in (using dlopen via the python 'import' command). So
> these symbols are eliminated because they are dead-code. So to suppress
> dead-code elimnation, I need to specify the flag --whole-archive to the
> linker. Now the linker will link in the whole archives that follow the
> '--whole-archive' flag. But gcc and bjam additional libraries to the end
> of the link-line. However not the whole of these libraries should be
> linked in. So this can be done with the flag '--no-whole-archive'.
>
> So currently my Jamfile looks like :
>
> lib system_lib : : <search>/usr/lib ;
> lib my_lib : my_source.cpp ;
> exe my_app : main.cpp my_lib :
> <toolset>gcc:<linkflags>-Wl,--export-dynamic,--whole-archive ;
>
> and produces following command-line
>
> gcc --Wl,--export-dynamic,--whole-archive -L/usr/lib -o my_app main.o
> my_lib.a -lsystem_lib ;
>
> And no I would like to add the flag -Wl,--no-whole-archive just in front
> of '-lsystem_lib' because for these system libs this flag can not be
> specified.
>
> The only option I see is to add '-Wl,--no-whole-archive' always in front
> of the system libs in boost/tools/build/v2/tools/gcc.jam or is there
> some other way ?

That's interesting problem, indeed. The first obvious question is if you
really need static library. I believe that if "my_lib.a" were shared library,
this problem and the "--whole-archive" flag would not be needed.

But I think you have some reasons for static lib.

Then, it think we cannot do anything automatically: after all you're using
platform specific <linkflags> backdoor. So, there are three options:

1. Add "reset-everything" option to the help of command line, but there's no
such option.
2. Failing (1) add "--no-whole-archive".
3. Since (2) is a bit messy, introduce <linkflags-final> or
<linkflags-trailing> or <linkflags-at-end> feature, which will be added to
the end of command line. Your Jamfile would look like:

exe my_app : main.cpp my_lib :
<toolset>gcc:<linkflags>-Wl,--export-dynamic,--whole-archive
<toolset>gcc:<linkflags-at-end>-Wl,--whole-archive
;

Comments and other suggestions are welcome...

BTW, I'm pretty sure it will take you very little time to add such a feature,
since it would be almost the same as the existing linkflags one. You might
want to try ;-)

- Volodya

 


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