View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014448CMakeCMakepublic2013-09-28 16:272014-03-05 09:58
ReporterZachary Deretsky 
Assigned ToBrad King 
PriorityhighSeveritymajorReproducibilityhave not tried
StatusclosedResolutionno change required 
PlatformLinuxOSUbuntu 12.04OS Version12.04
Product VersionCMake 2.8.11.2 
Target VersionFixed in Version 
Summary0014448: Cmake picks up the wrong compiler at the startup
DescriptionI 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".
TagsNo tags attached.
Attached Files

 Relationships
related to 0014445closedClinton Stimpson Does not build with Qt 5.1.0, same as issue 0014142 

  Notes
(0033925)
Rolf Eike Beer (developer)
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 (reporter)
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 (manager)
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 (reporter)
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 (manager)
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 (manager)
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 (reporter)
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 (manager)
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 (manager)
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 (reporter)
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 (manager)
2014-03-05 09:58

Closing resolved issues that have not been updated in more than 4 months

 Issue History
Date Modified Username Field Change
2013-09-28 16:27 Zachary Deretsky New Issue
2013-09-29 04:19 Rolf Eike Beer Note Added: 0033925
2013-09-29 14:32 Zachary Deretsky Note Added: 0033927
2013-09-30 08:31 Brad King Relationship added related to 0014445
2013-09-30 08:38 Brad King Note Added: 0033933
2013-09-30 08:46 Brad King Assigned To => Brad King
2013-09-30 08:46 Brad King Status new => resolved
2013-09-30 08:46 Brad King Resolution open => no change required
2013-09-30 15:27 Zachary Deretsky Note Added: 0033951
2013-09-30 15:27 Zachary Deretsky Status resolved => feedback
2013-09-30 15:27 Zachary Deretsky Resolution no change required => reopened
2013-09-30 16:02 Brad King Note Added: 0033952
2013-09-30 16:05 Brad King Note Added: 0033953
2013-10-01 16:47 Zachary Deretsky Note Added: 0033961
2013-10-01 16:47 Zachary Deretsky Status feedback => assigned
2013-10-01 16:56 Brad King Note Added: 0033962
2013-10-01 16:57 Brad King Note Added: 0033963
2013-10-01 18:07 Zachary Deretsky Note Added: 0033964
2013-10-02 08:14 Brad King Status assigned => resolved
2013-10-02 08:14 Brad King Resolution reopened => no change required
2014-03-05 09:58 Robert Maynard Note Added: 0035274
2014-03-05 09:58 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team