[CMake] ExternalProject with target_link_library produces incorrect linking?

Brad King brad.king at kitware.com
Tue Dec 9 14:30:06 EST 2014


On 12/09/2014 12:26 PM, J. Caleb Wherry wrote:
> add_library(ExtLib SHARED IMPORTED)
> set_property(TARGET ExtLib PROPERTY IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/${EXT_LIB_NAME}")
> add_dependencies(ExtLib ExtLibBuild)

Thanks for the complete/simple example.  The problem is that
the libExtLib.so file built by the external project does not
have DT_SONAME set by the linker.  When a linker is given a
path to a shared library file that has no soname then the path
is copied into the DT_NEEDED field of the consumer since it
has no soname to use for that.

There are two solutions:

1. Make sure DT_SONAME gets set properly by the external build system.

2. Tell CMake that the imported library file has no soname:

    set_property(TARGET ExtLib PROPERTY IMPORTED_NO_SONAME 1)

   CMake will then link it via -lExtLib and the linker will not
   store the path to the file in DT_NEEDED but only the file name.

Either of these should resolve the issue.  Number 1 is cleaner.

-Brad



More information about the CMake mailing list