[CMake] Transitive linking and imported targets

Tobias Rudolph tobias.rudolph at artorg.unibe.ch
Tue Mar 31 16:56:05 EDT 2009


On Mar 31, 2009, at 21:10, Hendrik Sattler wrote:

> Am Dienstag 31 März 2009 19:48:49 schrieb Tobias Rudolph:
>> ----
>> add_library( iLib SHARED IMPORTED )
>> set_target_properties( iLib PROPERTIES IMPORTED_LOCATION "/opt/local/
>> lib/libzip.dylib" )
>>
>> add_library( libFoo SHARED foo.cpp )
>> target_link_libraries( libFoo iLib )
>> ----
>>
>> According to the documentation, the imported target (iLib) is only
>> know within libFoo and its subdirectories. So, when I try to link
>> 'TestApp', it fails because the linker is looking for 'iLib' rather
>> than '/opt/local/lib/libzip.dylib' due transitive linking (I  
>> suspect).
>>
>> Is that intended behavior?
>
> Not sure but you don't need to link to iLib if you already link to  
> libFoo
> unless libFoo exports interfaces from iLib.
> See LINK_INTERFACE_LIBRARIES property.
>
> HS
>
Well, that's the point. The link dependencies are:
TestApp --> libFoo --> iLib (imported)

Since TestApp links against target libFoo, TestApp also links  
(transitively) against iLib, which is not know as an imported target  
at that point. See documentation of "target_link_libraries" for  
reference.

cheers,
Tobias


More information about the CMake mailing list