MantisBT - CMake
View Issue Details
0014448CMakeCMakepublic2013-09-28 16:272014-03-05 09:58
Zachary Deretsky 
Brad King 
highmajorhave not tried
closedno change required 
LinuxUbuntu 12.0412.04
CMake 2.8.11.2 
 
0014448: Cmake picks up the wrong compiler at the startup
I built cmake-2.8.12-rc3 with bootstrap -- -DBUILD_TESTING=FALSE and I encounter further problems. Let me explain, bear with me.

We have been building a fairly large package continuously and successfully for a couple of years with Cmake 2.8.8.
We are using our own tool chain including binutils 2.23.2 and gcc 4.6.3.
The reason is that our code has to be built and run on the Amazon cloud computers and on the local PCs, so we need very tight control on both the tools and the libraries we link with.

Now with the cmake-2.8.12-rc3 I just built I get a cmake error below. I repeat, our code builds perfectly well with Cmake 2.8.8. Cmake picks up the correct ld, but insists on using /usr/bin/cc. When I moved /usr/bin/cc to /usr/bin/cc_tmp cmake tells me to:

CMake Error: your C compiler: "/usr/bin/cc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.

I set
 set(${CMAKE_C_COMPILER} "/AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/bin/gcc")

at the top of CMakeLists.txt file, it did not help.

Is there way to force cmake use the compiler above? Thank you, Zach.


zach@cloud1-12:~/p5/arptop/arp/build$ cmake ..
-- The C compiler identification is GNU 4.6.3
-- The CXX compiler identification is GNU 4.6.3
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- broken
CMake Error at /AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/stow/cmake-2.8.12-rc3/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "/usr/bin/cc" is not able to compile a simple test program.

  It fails with the following output:

   Change Dir: /home/zach/p5/arptop/arp/build/CMakeFiles/CMakeTmp

  

  Run Build Command:/usr/bin/make "cmTryCompileExec2304154031/fast"

  /usr/bin/make -f CMakeFiles/cmTryCompileExec2304154031.dir/build.make
  CMakeFiles/cmTryCompileExec2304154031.dir/build

  make[1]: Entering directory
  `/home/zach/p5/arptop/arp/build/CMakeFiles/CMakeTmp'

  
  /AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/stow/cmake-2.8.12-rc3/bin/cmake
  -E cmake_progress_report
  /home/zach/p5/arptop/arp/build/CMakeFiles/CMakeTmp/CMakeFiles 1

  Building C object
  CMakeFiles/cmTryCompileExec2304154031.dir/testCCompiler.c.o

  /usr/bin/cc -o CMakeFiles/cmTryCompileExec2304154031.dir/testCCompiler.c.o
  -c /home/zach/p5/arptop/arp/build/CMakeFiles/CMakeTmp/testCCompiler.c

  Linking C executable cmTryCompileExec2304154031

  
  /AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/stow/cmake-2.8.12-rc3/bin/cmake
  -E cmake_link_script CMakeFiles/cmTryCompileExec2304154031.dir/link.txt
  --verbose=1

  /usr/bin/cc
  -L/AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/lib64
  -L/AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/lib
  CMakeFiles/cmTryCompileExec2304154031.dir/testCCompiler.c.o -o
  cmTryCompileExec2304154031 -rdynamic

  /AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/bin/ld:
  this linker was not configured to use sysroots

  collect2: ld returned 1 exit status

  make[1]: Leaving directory
  `/home/zach/p5/arptop/arp/build/CMakeFiles/CMakeTmp'

  make[1]: *** [cmTryCompileExec2304154031] Error 1

  make: *** [cmTryCompileExec2304154031/fast] Error 2

  

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  


-- Configuring incomplete, errors occurred!
See also "/home/zach/p5/arptop/arp/build/CMakeFiles/CMakeOutput.log".
See also "/home/zach/p5/arptop/arp/build/CMakeFiles/CMakeError.log".
No tags attached.
related to 0014445closed Clinton Stimpson Does not build with Qt 5.1.0, same as issue 0014142 
Issue History
2013-09-28 16:27Zachary DeretskyNew Issue
2013-09-29 04:19Rolf Eike BeerNote Added: 0033925
2013-09-29 14:32Zachary DeretskyNote Added: 0033927
2013-09-30 08:31Brad KingRelationship addedrelated to 0014445
2013-09-30 08:38Brad KingNote Added: 0033933
2013-09-30 08:46Brad KingAssigned To => Brad King
2013-09-30 08:46Brad KingStatusnew => resolved
2013-09-30 08:46Brad KingResolutionopen => no change required
2013-09-30 15:27Zachary DeretskyNote Added: 0033951
2013-09-30 15:27Zachary DeretskyStatusresolved => feedback
2013-09-30 15:27Zachary DeretskyResolutionno change required => reopened
2013-09-30 16:02Brad KingNote Added: 0033952
2013-09-30 16:05Brad KingNote Added: 0033953
2013-10-01 16:47Zachary DeretskyNote Added: 0033961
2013-10-01 16:47Zachary DeretskyStatusfeedback => assigned
2013-10-01 16:56Brad KingNote Added: 0033962
2013-10-01 16:57Brad KingNote Added: 0033963
2013-10-01 18:07Zachary DeretskyNote Added: 0033964
2013-10-02 08:14Brad KingStatusassigned => resolved
2013-10-02 08:14Brad KingResolutionreopened => no change required
2014-03-05 09:58Robert MaynardNote Added: 0035274
2014-03-05 09:58Robert MaynardStatusresolved => closed

Notes
(0033925)
Rolf Eike Beer   
2013-09-29 04:19   
Why don't you just set the CC environment variable before calling CMake the first time in an empty build directory?
(0033927)
Zachary Deretsky   
2013-09-29 14:32   
Rolf,

your suggestion helped, thank you.
I still have a problem down the line, I am investigating whether it unrelated to this one.

Zach.
(0033933)
Brad King   
2013-09-30 08:38   
If "/AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/bin/gcc" is in your PATH and was picked up by CMake < 2.8.10, and there is no "cc" next to it, then the probable cause of this change in behavior is this commit:

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

Read the entire commit message for a full explanation and justification, but the summary is CMake prefers "cc" over "gcc" now for default compiler selection.

The proper way to select a compiler from the command line is to set CC before calling CMake.

If you want to do it from the project then you can

 set(CMAKE_C_COMPILER "/AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/bin/gcc")

at the top of the CMakeLists.txt before the first project() or enable_language() command.

For highly customized toolchain specification you could treat this as a cross-compiling case and use a toolchain file:

 http://www.cmake.org/Wiki/CMake_Cross_Compiling [^]
(0033951)
Zachary Deretsky   
2013-09-30 15:27   
Brad,
for the benefit of others: exporting CC outside of cmake does work, but
set(CMAKE_C_COMPILER $myCompiler) on top of CMakeLists.txt does NOT work.

To test on Linux just do sudo mv /usr/bin/cc /usr/bin/my_cc and run cmake with
set(CMAKE_C_COMPILER /usr/bin/my_cc)

Per justification you suggested me to read it is important to replace cmake message
>>CMake Error: your C compiler: "/usr/bin/cc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name

with the message suggesting to export CC=... outside of cmake.

There would be no need to file a bug if this instruction was given.

Also, the fact that cmake picks up ld from its first occurrence on the $PATH but does not pick gcc from there is inconsistent IMHO. Better behavior would be to pick cc or gcc, whichever comes first on the $PATH and to make sure both compiler and linker come from the same place.

Regards, Zach.
(0033952)
Brad King   
2013-09-30 16:02   
Re 0014448:0033951: Setting CMAKE_C_COMPILER in CMakeLists.txt works for me. Please post a minimal CMakeLists.txt for which it does not work.
(0033953)
Brad King   
2013-09-30 16:05   
Re 0014448:0033951: As for picking up the first compiler in PATH, there could be 100 different vendor-specific compiler names to choose. There is no reason that "gcc" is better than "cl" or "pathcc". That was the point of the switch to preferring the system compiler name "cc". If you need a specific compiler, then pick it explicitly.

FYI, you can also do

 cmake -DCMAKE_C_COMPILER="/AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/bin/gcc" ...

which is actually what the "Please set ..." message means.
(0033961)
Zachary Deretsky   
2013-10-01 16:47   
Re (0033952)
Here is my CMakeLists.txt:

cmake_minimum_required (VERSION 2.8)
set(CMAKE_C_COMPILER "/AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/bin/gcc")

add_executable(sqrt sqrt.cpp)

Here is the output, note the result of "which gcc" down below to make sure I entered the correct path and note that ld is taken from that path.

zach@cloud1-12:~/CC/build$ cmake ..
-- The C compiler identification is GNU 4.6.3
-- The CXX compiler identification is GNU 4.6.3
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- broken
CMake Error at /AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/stow/cmake-2.8.12-rc3/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "/usr/bin/cc" is not able to compile a simple test program.

  It fails with the following output:

   Change Dir: /home/zach/CC/build/CMakeFiles/CMakeTmp

  

  Run Build Command:/usr/bin/make "cmTryCompileExec2844372356/fast"

  /usr/bin/make -f CMakeFiles/cmTryCompileExec2844372356.dir/build.make
  CMakeFiles/cmTryCompileExec2844372356.dir/build

  make[1]: Entering directory `/home/zach/CC/build/CMakeFiles/CMakeTmp'

  
  /AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/stow/cmake-2.8.12-rc3/bin/cmake
  -E cmake_progress_report /home/zach/CC/build/CMakeFiles/CMakeTmp/CMakeFiles
  1

  Building C object
  CMakeFiles/cmTryCompileExec2844372356.dir/testCCompiler.c.o

  /usr/bin/cc -o CMakeFiles/cmTryCompileExec2844372356.dir/testCCompiler.c.o
  -c /home/zach/CC/build/CMakeFiles/CMakeTmp/testCCompiler.c

  Linking C executable cmTryCompileExec2844372356

  
  /AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/stow/cmake-2.8.12-rc3/bin/cmake
  -E cmake_link_script CMakeFiles/cmTryCompileExec2844372356.dir/link.txt
  --verbose=1

  /usr/bin/cc
  -L/AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/lib64
  -L/AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/lib
  CMakeFiles/cmTryCompileExec2844372356.dir/testCCompiler.c.o -o
  cmTryCompileExec2844372356 -rdynamic

  /AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/bin/ld:
  this linker was not configured to use sysroots

  collect2: ld returned 1 exit status

  make[1]: Leaving directory `/home/zach/CC/build/CMakeFiles/CMakeTmp'

  make[1]: *** [cmTryCompileExec2844372356] Error 1

  make: *** [cmTryCompileExec2844372356/fast] Error 2

  

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  


-- Configuring incomplete, errors occurred!
See also "/home/zach/CC/build/CMakeFiles/CMakeOutput.log".
See also "/home/zach/CC/build/CMakeFiles/CMakeError.log".
zach@cloud1-12:~/CC/build$ which gcc
/AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/bin/gcc
zach@cloud1-12:~/CC/build$ echo $PATH
/home/zach/bin:.:/AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/bin:/AZ/x86_64/kernel-3.2.0-25-virtual/glibc-2.15/2013-09-19-12.16.39/processing-1.5.1:/AZ/cmtools/bin:/home/zach/p4/tools/sketchupx/3.0/scripts:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin:/home/zach/bin:/home/zach/p4/env/linux/bin:/home/zach/p4/env/common/bin:/opt/p4/bin
zach@cloud1-12:~/CC/build$
(0033962)
Brad King   
2013-10-01 16:56   
Add a project() call:

 cmake_minimum_required (VERSION 2.8)
 set(CMAKE_C_COMPILER "...")
 project(example)
 add_executable(sqrt sqrt.cpp)

If there is no project() call CMake inserts one at the top (line 0). This is to make hello-world examples easier, but real projects should call projects() explicitly.
(0033963)
Brad King   
2013-10-01 16:57   
FYI, CMake does not call "ld" directly so it is not CMake that is taking it from the path. CMake invokes the compiler front-end to do the linking, and that picks the linker.
(0033964)
Zachary Deretsky   
2013-10-01 18:07   
Adding a project call:
>cmake_minimum_required(VERSION 2.8.11)
>set(CMAKE_C_COMPILER $ENV{AZ_TOOL_PATH}/bin/gcc)
>project(arp)

did make it work.
We were running rather complicated hierarchical setup with cmake 2.8.8 for two years and I never knew it was necessary. I have to learn what is the meaning and purpose of this call.

Thank you, Zach.
(0035274)
Robert Maynard   
2014-03-05 09:58   
Closing resolved issues that have not been updated in more than 4 months