[CMake] Using CMAKE_DL_LIBS on an imported target

Björn Pollex bjoern.pollex at posteo.de
Wed Jun 7 07:40:34 EDT 2017


Hi everyone,

I’m reposting here the same question I’ve already posted on Stackoverflow [1], in the hopes of reaching a more appropriate audience.


I have an imported target (an external library) that required -ldl, so I'm adding ${CMAKE_DL_LIBS} to the INTERFACE_LINK_LIBRARIES property like this:

    set_property(TARGET some_lib PROPERTY
        INTERFACE_LINK_LIBRARIES Threads::Threads ${CMAKE_DL_LIBS})

Now, when I use that target elsewhere, like this:

    target_link_libraries(my_target some_lib)

I get a linker error that `dladdr` is undefined. However, when I explicitly add CMAKE_DL_LIBS to that target, it works:

    target_link_libraries(my_target some_lib ${CMAKE_DL_LIBS})

So it seems that this is not propagate correctly. Is there a way to make this work without explicitly specifying CMAKE_DL_LIBS in the using target?


Kind regards,

	Björn Pollex


[1]: https://stackoverflow.com/questions/44410924/using-cmake-dl-libs-on-an-imported-target


More information about the CMake mailing list