[CMake] CLANG vs GCC when linking executables
Patrick Boettcher
patrick.boettcher at posteo.de
Fri May 12 10:57:25 EDT 2017
Hi list,
I'm trying to link an executable with a locally build and imported
dynamic library. The link-code generated by CMake differs when
using GCC and Clang in regards to the rpath-options:
This is my cmake-code for importing the library (this code is actually
generated by using export() )
add_library(systemc INTERFACE IMPORTED)
set_target_properties(systemc PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "SC_INCLUDE_FX"
INTERFACE_COMPILE_OPTIONS "-Wno-deprecated-declarations"
INTERFACE_INCLUDE_DIRECTORIES "/local/path/include"
INTERFACE_LINK_LIBRARIES "/local/path/lib/libsystemc.so")
add_executable(testsc test.cpp)
target_link_libraries(testsc systemc)
When now running cmake in a build-dir which uses by default gcc the
link-command contains:
/usr/bin/g++ CMakeFiles/testsc.dir/test.cpp.o -o testsc \
-Wl,-rpath,/local/path/lib /local/path/lib/libsystemc.so
doing the same with clang++ as CXX-compiler (CXX=clang++ cmake
<src-path>) gives me a linker command not containing the -rpath-option:
clang++ CMakeFiles/testsc.dir/test.cpp.o -o testsc \
/local/path/lib/libsystemc.so
The link-process works, but when running the executable inside the
build-dir it is unable to find the library as neither the rpath is set
nor is this library-path known by the dynamic loader.
Is there anything I can do? Is this behavior expected? How should the
RPATH being handled when clang is used.
best regards,
--
Patrick.
More information about the CMake
mailing list