MantisBT - CMake
View Issue Details
0013960CMakeCMakepublic2013-02-27 14:362016-06-10 14:31
Lebedev Roman 
Kitware Robot 
normalminoralways
closedmoved 
GNU/LinuxGentoo
CMake 2.8.10.2 
 
0013960: CMake does not always detect clang toolchain linker
dev-util/cmake-2.8.10.2-r2
sys-devel/clang, sys-devel/llvm checked out from trunk on 11:00:56 PM 02/27/2013
This command doesn't works: CC=clang CXX=clang++ CFLAGS="-O0 -flto" CXXFLAGS="${CFLAGS}" CPPFLAGS="${CFLAGS}" cmake ../ &>build.log; make -i -k -j7 VERBOSE=1 &>>build.log
But this one does: CC=clang CXX=clang++ CFLAGS="-O0 -flto" CXXFLAGS="${CFLAGS}" CPPFLAGS="${CFLAGS}" cmake -D_CMAKE_TOOLCHAIN_PREFIX=x86_64-pc-linux-gnu- ../ &>build.log; make -i -k -j7 VERBOSE=1 &>>build.log
No tags attached.
related to 0015737closed Brad King Use of redhat-hardened-ld breaks CMake's Fortran compiler library detection for gfortran 
? CMakeCXXCompiler-bad.cmake (1,401) 2013-02-27 14:36
https://public.kitware.com/Bug/file/4651/CMakeCXXCompiler-bad.cmake
log CMakeOutput-bad.log (23,361) 2013-02-27 14:37
https://public.kitware.com/Bug/file/4652/CMakeOutput-bad.log
? CMakeCXXCompiler-good.cmake (1,572) 2013-02-27 14:37
https://public.kitware.com/Bug/file/4653/CMakeCXXCompiler-good.cmake
log CMakeOutput-good.log (28,534) 2013-02-27 14:37
https://public.kitware.com/Bug/file/4654/CMakeOutput-good.log
log build-bad.log (835,004) 2013-02-27 14:40
https://public.kitware.com/Bug/file/4655/build-bad.log
log build-good.log (786,446) 2013-02-27 14:41
https://public.kitware.com/Bug/file/4656/build-good.log
log CMakeError-bad.log (25,748) 2013-02-27 15:34
https://public.kitware.com/Bug/file/4657/CMakeError-bad.log
log CMakeError-good.log (25,734) 2013-02-27 15:39
https://public.kitware.com/Bug/file/4658/CMakeError-good.log
Issue History
2013-02-27 14:36Lebedev RomanNew Issue
2013-02-27 14:36Lebedev RomanFile Added: CMakeCXXCompiler-bad.cmake
2013-02-27 14:37Lebedev RomanFile Added: CMakeOutput-bad.log
2013-02-27 14:37Lebedev RomanFile Added: CMakeCXXCompiler-good.cmake
2013-02-27 14:37Lebedev RomanFile Added: CMakeOutput-good.log
2013-02-27 14:40Lebedev RomanFile Added: build-bad.log
2013-02-27 14:41Lebedev RomanFile Added: build-good.log
2013-02-27 14:48Lebedev RomanNote Added: 0032398
2013-02-27 14:58Bill HoffmanNote Added: 0032399
2013-02-27 15:24Brad KingNote Added: 0032400
2013-02-27 15:28Brad KingNote Added: 0032401
2013-02-27 15:30Brad KingNote Added: 0032402
2013-02-27 15:31Brad KingSummaryBuilding of Darktable master by clang fails => CMake does not always detect clang toolchain linker
2013-02-27 15:34Lebedev RomanFile Added: CMakeError-bad.log
2013-02-27 15:36Brad KingNote Added: 0032403
2013-02-27 15:39Lebedev RomanFile Added: CMakeError-good.log
2013-05-04 19:17Matthias MaierNote Added: 0032973
2013-05-06 09:00Brad KingNote Added: 0032977
2013-05-06 09:00Brad KingStatusnew => backlog
2015-09-11 13:32Brad KingRelationship addedrelated to 0015737
2016-06-10 14:28Kitware RobotNote Added: 0042240
2016-06-10 14:28Kitware RobotStatusbacklog => resolved
2016-06-10 14:28Kitware RobotResolutionopen => moved
2016-06-10 14:28Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0032398)
Lebedev Roman   
2013-02-27 14:48   
The problem lies in empty CMAKE_CXX_IMPLICIT_LINK_LIBRARIES
(0032399)
Bill Hoffman   
2013-02-27 14:58   
In the one that works this library links to c++ and m:

Linking C shared library libdarktable.so
-lstdc++ -lm

The other is missing that.

set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "stdc++;m;c")
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "/usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2;/usr/lib64;/lib64;/usr/x86_64-pc-linux-gnu/lib;/lib;/usr/lib")
vs

set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "")


The trouble seems to be in the CMakeOutput-bad.log file here:


  ignore line: [ "/usr/bin/x86_64-pc-linux-gnu-ld" -export-dynamic --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o cmTryCompileExec1866823997 /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/crtbegin.o -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2 -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/../../.. -L/lib -L/usr/lib -plugin /usr/bin/../lib64/llvm/LLVMgold.so -plugin-opt=mcpu=x86-64 CMakeFiles/cmTryCompileExec1866823997.dir/CMakeCXXCompilerABI.cpp.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/crtend.o /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../lib64/crtn.o]
  ignore line: [gmake[1]: Leaving directory `/home/pinipini/darktable/build/CMakeFiles/CMakeTmp']
  ignore line: []


Working one does this:

  link line: [ "/usr/bin/x86_64-pc-linux-gnu-ld" -export-dynamic --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o cmTryCompileExec3835301014 /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/crtbegin.o -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2 -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/../../.. -L/lib -L/usr/lib -plugin /usr/bin/../lib64/llvm/LLVMgold.so -plugin-opt=mcpu=x86-64 CMakeFiles/cmTryCompileExec3835301014.dir/CMakeCXXCompilerABI.cpp.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/crtend.o /usr/lib64/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../lib64/crtn.o]
(0032400)
Brad King   
2013-02-27 15:24   
Please attach CMakeFiles/CMakeOutput.log and CMakeFiles/CMakeError.log from the failing and working trees.
(0032401)
Brad King   
2013-02-27 15:28   
Oops, I see CMakeOutput.log is already there.

From CMakeOutput-bad.log:

 Parsed CXX implicit link information from above output:
   link line regex: [^( *|.*[/\])(ld|ld|collect2)[^/\]*( |$)]

From CMakeOutput-good.log:

 Parsed CXX implicit link information from above output:
   link line regex: [^( *|.*[/\])(x86_64-pc-linux-gnu-ld|ld|collect2)[^/\]*( |$)]

The bad one has CMAKE_LINKER set to "ld" and the good one has it set to x86_64-pc-linux-gnu-ld.
(0032402)
Brad King   
2013-02-27 15:30   
Re 0013960:0032401: The good one found the "right" linker because of your -D_CMAKE_TOOLCHAIN_PREFIX=x86_64-pc-linux-gnu- workaround.

Any idea how we can find the right linker for this toolchain automatically?
(0032403)
Brad King   
2013-02-27 15:36   
Re 0013960:0032402: While we still need an approach to set CMAKE_LINKER correctly, here is a patch that may help find the implicit link information even without the proper CMAKE_LINKER in this case.

diff --git a/Modules/CMakeParseImplicitLinkInfo.cmake b/Modules/CMakeParseImplicitLinkInfo.cmake                               

index 80e0218..fa03630 100644
--- a/Modules/CMakeParseImplicitLinkInfo.cmake
+++ b/Modules/CMakeParseImplicitLinkInfo.cmake
@@ -29,7 +29,7 @@ function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj
   endif()
   # Construct a regex to match linker lines.  It must match both the
   # whole line and just the command (argv[0]).
-  set(linker_regex "^( *|.*[/\\])(${linker}|ld|collect2)[^/\\]*( |$)")
+  set(linker_regex "^( *|.*[/\\])(${linker}|([^/\\]+-)?ld|collect2)[^/\\]*( |$)")
   set(linker_exclude_regex "collect2 version ")
   set(log "${log}  link line regex: [${linker_regex}]\n")
   string(REGEX REPLACE "\r?\n" ";" output_lines "${text}")
(0032973)
Matthias Maier   
2013-05-04 19:17   
I can confirm this issue.
The workaround by Brad King in the last comment - relaxing the linker_regex in CMakeParseImplicitLinkInfo.cmake does mitigate the problem.
(0032977)
Brad King   
2013-05-06 09:00   
I've applied the patch from 0013960:0032403:

 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a2bc47df [^]

Moving this issue to backlog for future handling of the larger problem of detecting CMAKE_LINKER.
(0042240)
Kitware Robot   
2016-06-10 14:28   
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.