[CMake] CLANG vs GCC when linking executables
Patrick Boettcher
patrick.boettcher at posteo.de
Fri May 12 11:30:16 EDT 2017
On Fri, 12 May 2017 16:57:25 +0200
Patrick Boettcher <patrick.boettcher at posteo.de> wrote:
> 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.
The problem only occurs when the compiler is coming from a custom build
from a custom path. Running
CXX=clang++ cmake <src-path>
makes cmake generate the correct link options.
CXX=/local/path/bin/clang++ cmake <src-path>
makes cmake generate wrong link options (without RPATH).
Seems to be related the compiler-ID which is wrongly determined or
something like that.
--
Patrick.
More information about the CMake
mailing list