[cmake-developers] GCC link options

J Decker d3ck0r at gmail.com
Wed Jul 25 14:12:46 EDT 2012


Same topic... slightly different question...

So I split the code from the main program and added it as another
static library, and it's last in the list... I would like to add
--whole-archive and --no-whole-archive around it... however it is not
working; it is injecting other libraries in it, and/or not picking up
the symbols I need it to.

This basically works... but then the library can't find symbols
specified, so I need to add a library after it...

target_link_libraries(  playcard --whole-archive
eltanin_sdl_deadstart_end --no-whole-archive )

But with the following line, the --no-whole-archive is put after the
${COMMON_LIBRARIES}....

target_link_libraries(  playcard --whole-archive
eltanin_sdl_deadstart_end --no-whole-archive ${COMMON_LIBRARIES} )
(the output link line looks like .....  libplaycard.a --whole-archive
eltanin_sdl_deadstart_end.a libcommon.a --no-whole-archive )

I don't see why this is.  I even split it, so in the playcard
Cmakelists I left...
target_link_libraries(  playcard -Wl,--whole-archive
eltanin_sdl_deadstart_end  )

and in the main I put ( or any combination fo the following lines -
even collapsing them to 1...)
target_link_libraries(  eltanin_sdl_deadstart_end ${COMMON_LIBRARIES} )
target_link_libraries(  eltanin_sdl_deadstart_end -Wl,--no-whole-archive )


but no matter which direction I put that... the external common lib
ends up between deadstart_end and --no-whole-archive...

if I don't put -Wl,--whole-archive this library is being omitted
entirely.... and adding used to the attribute didn't make it get
included.

blah... if I grab the command line and manually add --whole-archive
--no-whole-archive

if the common library gets put inbetween, then I get a ton of
duplicately defined symbols (by the same library) because the
-lcommon.library.thing is referenced already multiple times in the
command line....

On Wed, Jul 25, 2012 at 5:03 AM, Brad King <brad.king at kitware.com> wro
te:
> On 07/24/2012 05:24 PM, J Decker wrote:
>> CMake Error at eltanin/sdlgui/src/eltanin_sdl/CMakeLists.txt:68
>> (target_link_libraries):
>>   Cannot specify link libraries for target "advapi32" which is not built by
>>   this project.
>
> If that library is not built by you why does it have a dependency
> on a symbol you provide such that your library must come after it?
>
It was just the last library in the list... no biggie.

>> Is there something I can do to make sure this specific library is
>> last?  That maybe someone needs to update the cmake scripts?
>
> There was some discussion of this a few years ago:
>
>  http://thread.gmane.org/gmane.comp.programming.tools.cmake.user/18883
>
>>> Alternatively, don't specify any target_link_libraries calls
>>> so that there are no indirect dependencies.
>> Where would I put the libraries then? as part of the sources?
>
> One giant target_link_libraries line for the final target that
> lists exactly the link line you want.
>
> -Brad



More information about the cmake-developers mailing list