[CMake] Linking to libraries that depend on other libraries
Andreas Pakulat
apaku at gmx.de
Thu May 17 17:28:42 EDT 2012
Hi,
On Thu, May 17, 2012 at 10:50 PM, David Doria <daviddoria at gmail.com> wrote:
> On Thu, May 17, 2012 at 2:18 AM, Petr Kmoch <petr.kmoch at gmail.com> wrote:
>
>> Hi David,
>>
>> there's a target property LINK_INTERFACE_LIBRARIES (and
>> per-configuration variants) which can be used for this purpose.
>> Starting with 2.8.7, target_link_libraries() also accepts
>> LINK_INTERFACE_LIBRARIES as a new argument mode, setting the property
>> instead of linking.
>>
>> Petr
>
>
> Petr,
>
> I tried the following, but in both cases (target_link_libraries
> and set_target_properties) I still get a linker error that it can't find
> TestB().
>
> cmake_minimum_required(VERSION 2.6)
> PROJECT(Test)
>
> add_library(TestB TestB.cpp)
>
> # TestA depends on TestB
> add_library(TestA TestA.cpp)
> #target_link_libraries(TestA LINK_INTERFACE_LIBRARIES TestB)
> set_target_properties(TestA PROPERTIES LINK_INTERFACE_LIBRARIES "TestB")
>
You forgot to link TestA to TestB here, I guess your c++ code currently
does not actually expose any dependency? Thats why cmake doesn't include
TestB when linking the executable.
The LINK_INTERFACES_LIBRARIES only helps cmake to decide when a particular
library doesn't need to be added to the linker-command for the executable.
By default cmake will link the executable against the libraries specified
by you and any libraries these link to - recursively. The property just
allows to disable this behaviour by defining which dependent libraries a
given library exposes in its public API and hence which dependent libraries
an executable might need to link against in addition to the main library.
Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120517/560a104f/attachment.htm>
More information about the CMake
mailing list