[CMake] static library linking

Steven Van Ingelgem steven at vaningelgem.be
Sun Jun 15 18:06:21 EDT 2008


I re-read my post and I gotta say I'm -again- unclear... Let me put this
more detailed:
===============
add_library(
somename
shared

a.cpp)
target_link_libraries(somename /somepath/lib100m.a)

add_library(
otherlib
shared

b.cpp)
target_link_libraries(otherlib somename)
===============

The first lib will link against "lib100m.a".

The second lib however will link against both "libsomename.so" and the
"lib100m.a"... The first lib-linking is correct, but the second one is not
as that's not what I want... I want to use the symbols in the "lib100m.a"
inside the first library, and use those to calculate stuff in there, but
they're of no use whatsoever inside the second shared library... Because
this one only uses symbols exported from the "libsomename.so", not from
"lib100m.a".


Hopefully that makes my issue more clear ;).


Greetings



2008/6/15 Steven Van Ingelgem <steven at vaningelgem.be>:

> Another issue I just noticed... If you link to an "add_library" or so, it
> will add all the target linked libraries of the original "add_library",
> which is rather incorrect imho because I don't want to link every library to
> a 100M static library, that is only compiled in in 1 shared library...
>
> Is there somehow I can turn this off?
>
>
> Thanks!
>
> 2008/6/15 Steven Van Ingelgem <steven at vaningelgem.be>:
>
>> Hmmm?
>>
>>
>>
>> I don't seem to be able to make it link correctly?
>>
>> I do:
>> set_property(TARGET ${SUB_PROJECT} PROPERTY IMPORTED_LOCATION ${PTHREAD}
>> ${RT} ${LIBC})
>>
>> But it's still somehow linking wrongly :(...
>>
>> What would be the correct line for this?
>>
>>
>> The weird thing is... When I turn it off (the linking), it still tries to
>> link against pthread, rt & libc... I have no idea why? Doesn't it regenerate
>> the makefiles when you modify the CMakeLists.txt?
>>
>>
>> Thanks
>>
>>
>>
>> 2008/6/15 Alan W. Irwin <irwin at beluga.phys.uvic.ca>:
>>
>>> On 2008-06-15 21:58+0200 Steven Van Ingelgem wrote:
>>>
>>>  Hi Alan,
>>>>
>>>>
>>>> It doesn't want to link with the -Bstatic... But it links nicely with
>>>> the
>>>> static paths...
>>>> In fact on the system is only 1 libpthread.a ... And that's not what is
>>>> getting linked against because it returns errors related to symbols
>>>> which
>>>> cannot be found in the .so (somehow).
>>>>
>>>> I have no idea what's going on, but getting a list of ld which libraries
>>>> it
>>>> will link would certainly be helpful.
>>>>
>>>
>>> Hi Steven:
>>>
>>> Brad's link
>>> http://www.cmake.org/Wiki/CMake_2.6_Notes#Linking_to_System_Librariesgives
>>> a lot of the relevant background as to why CMake specifies linking the
>>> way
>>> it does and at the end gives you a way to do exactly what you want
>>> (specify
>>> the exact static library).  My thanks to Brad for drawing my attention to
>>> that link.
>>>
>>> But if you (Steven) are curious enough to further pursue the -l issue
>>> which
>>> you seem to have discovered (which might be a good idea anyhow since
>>> something may be fundamentally wrong with your linker version), please
>>> let
>>> me know the complete link command (and any associated warning or error
>>> messages).  To do that use the make VERBOSE=1 option. Please also send
>>> the
>>> complete results of running "ldd -r" on the executable that is produced.
>>> (If
>>> there is a linking error, you can run the linking command again by hand
>>> using the --noinhibit-exec option to generate an executable regardless of
>>> most errors.)
>>>
>>>
>>> Alan
>>> __________________________
>>> Alan W. Irwin
>>>
>>> Astronomical research affiliation with Department of Physics and
>>> Astronomy,
>>> University of Victoria (astrowww.phys.uvic.ca).
>>>
>>> Programming affiliations with the FreeEOS equation-of-state
>>> implementation
>>> for stellar interiors (freeeos.sf.net); PLplot scientific plotting
>>> software
>>> package (plplot.org); the libLASi project (unifont.org/lasi); the Loads
>>> of
>>> Linux Links project (loll.sf.net); and the Linux Brochure Project
>>> (lbproject.sf.net).
>>> __________________________
>>>
>>> Linux-powered Science
>>> __________________________
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080616/b338c026/attachment-0001.htm>


More information about the CMake mailing list