MantisBT - CMake
View Issue Details
0016059CMakeCMakepublic2016-04-12 12:002016-06-10 14:31
Antonio 
Kitware Robot 
normalminoralways
closedmoved 
X86Windows7
CMake 3.4.1 
 
0016059: It is not possible to specify a linker different from the compiler to link a shared library
In some situations, it might be convenient to specify a different linker than the compiler. For example, for llvm combined with mingw, compiling with clang and linking with gcc would work. The workaround proposed here https://cmake.org/pipermail/cmake/2014-August/058268.html [^] does not seem to work.
Requires 2 compilers to be there. In the attached project,
Configuring with
D:\dummyProj\build> cmake ..\src -G "Eclipse CDT4 - Ninja" -DCMAKE_TOOLCHAIN_FILE=..\src\Toolchain-LLVM.cmake -DCMAKE_LINKER=C:/Programs/mingw32_493_posix_dwarf/bin/g++.exe -DCMAKE_CXX_LINK_EXECUTABLE="<CMAKE_LINKER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" -DCMAKE_CXX_CREATE_SHARED_LIBRARY="<CMAKE_LINKER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"

Building will anyway lead to the following commands to be generated:
[1/2] C:\Programs\LLVM\bin\clang++.exe -Ddummy_EXPORTS -MMD -MT CMakeFiles/dummy.dir/dummy.cpp.obj -MF CMakeFiles/dummy.dir/dummy.cpp.obj.d -o CMakeFiles/dummy.dir/dummy.cpp.obj -c D:/dummyProj/src/dummy.cpp
[2/2] cmd.exe /C "cd . && C:\Programs\LLVM\bin\clang++.exe -shared -o libdummy.dll -Wl,--out-implib,libdummy.dll.a -Wl,--major-image-version,0,--minor-image-version,0 CMakeFiles/dummy.dir/dummy.cpp.obj -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
FAILED: cmd.exe /C "cd . && C:\Programs\LLVM\bin\clang++.exe -shared -o libdummy.dll -Wl,--out-implib,libdummy.dll.a -Wl,--major-image-version,0,--minor-image-version,0 CMakeFiles/dummy.dir/dummy.cpp.obj -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:\Programs\mingw32_493_posix_dwarf\i686-w64-mingw32\lib/libmingw32.a(lib32_libmingw32_a-pseudo-reloc.o):pseudo-reloc.c:(.text+0x1d6): undefined reference to `__chkstk_ms'

clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

ninja: build stopped: subcommand failed.

The first command is correct, the second doesn't use g++ to link as desired. Linking succeeds if g++ is replaced in the command line.
Clang, CMake, linker, LLVM
zip dummyProj.zip (84,997) 2016-04-12 12:00
https://public.kitware.com/Bug/file/5673/*
Issue History
2016-04-12 12:00AntonioNew Issue
2016-04-12 12:00AntonioFile Added: dummyProj.zip
2016-04-20 09:28AntonioTag Attached: Clang
2016-04-20 09:28AntonioTag Attached: linker
2016-04-20 09:28AntonioTag Attached: locale
2016-04-20 09:28AntonioTag Detached: locale
2016-04-20 09:29AntonioTag Attached: CMake
2016-04-20 09:29AntonioTag Attached: LLVM
2016-06-10 14:29Kitware RobotNote Added: 0042980
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0042980)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.