Broken CMake and GCC under OS X

2019-04-09 19:52发布

When running configure in cmake-gui on my OS X platform, I get the following error occurring:

The C compiler identification is GNU
The CXX compiler identification is GNU
Checking whether C compiler has -isysroot
Checking whether C compiler has -isysroot - yes
Checking whether C compiler supports OSX deployment target flag
Checking whether C compiler supports OSX deployment target flag - yes
Check for working C compiler: /usr/bin/gcc-4.0
Check for working C compiler: /usr/bin/gcc-4.0 -- broken
CMake Error at /Applications/CMake 2.8-2.app/Contents/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
  The C compiler "/usr/bin/gcc-4.0" is not able to compile a simple test
  program.

  It fails with the following output:

   Change Dir: /Users/bill/Desktop/cmake_test/build/CMakeFiles/CMakeTmp

  Run Build Command:/opt/local/bin/gmake "cmTryCompileExec/fast"

  /opt/local/bin/gmake -f CMakeFiles/cmTryCompileExec.dir/build.make
  CMakeFiles/cmTryCompileExec.dir/build

  gmake[1]: Entering directory
  `/Users/bill/Desktop/cmake_test/build/CMakeFiles/CMakeTmp'

  "/Applications/CMake 2.8-2.app/Contents/bin/cmake" -E cmake_progress_report
  /Users/bill/Desktop/cmake_test/build/CMakeFiles/CMakeTmp/CMakeFiles 1

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

  /usr/bin/gcc-4.0 -isysroot -o
  CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o -c
  /Users/bill/Desktop/cmake_test/build/CMakeFiles/CMakeTmp/testCCompiler.c

  i686-apple-darwin10-gcc-4.0.1:
  CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o: No such file or
  directory

    <snip>

From looking at forums, etc. on the Internet, I have established that this could be to do with my PATH variable. Here is my PATH variable for analysis:

! echo $PATH
/Library/Frameworks/Python.framework/Versions/Current/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/sw/bin:/sw/sbin:/Applications/MATLAB_R2012a.app/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/X11/bin:/usr/X11R6/bin

This path variable has recently changed when I configured Python, and I think that the GCC problems must have sprung up at the same sort of time. What could be wrong with my system installation for this to be occurring?


Some more details. The build program specified by CMAKE_MAKE_PROGRAM is /opt/local/bin/gmake.

I have also discovered that these errors are only thrown when running Configure in cmake-gui. On the command line (running cmake .. from a build folder), the configuration completes fine:

! cmake ..
-- The C compiler identification is GNU 4.0.1
-- The CXX compiler identification is GNU 4.2.1
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /usr/bin/gcc-4.0
-- Check for working C compiler: /usr/bin/gcc-4.0 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done

However, compilation is not always successful when using some libraries - see for example this question I have asked here. I therefore think something might still be going wrong in the cmake process.

标签: c gcc cmake
2条回答
甜甜的少女心
2楼-- · 2019-04-09 20:41

I also came across this issue, and I have fixed it by setting the correct CXXFLAGS and CPPFLAGS. I think you should also check it.

One simple solution would be:

CPPFLAGS := $(CPPFLAGS) $(CFLAGS) CXXFLAGS := $(CXXFLAGS) $(CFLAGS)

Or you should check whether your PATH is correct. You should be able to find the CXX compiler and C compiler in your current shell.

查看更多
淡お忘
3楼-- · 2019-04-09 20:49

Some observations about your question, which may lead you to a solution...

You are using CMake 2.8.2, which is fairly old, as far as CMake versions go. Try with 2.8.11 or a release candidate of the upcoming 2.8.12 to see if the problem still exists. If nothing else, perhaps you'll get a better error message.

See this question and answer and its links to see about the various ways of guaranteeing consistent PATH values between command line environments and GUI applications launched via other means on the Mac: How do I set the global PATH environment variable on OS X?

The CMake GUI does not necessarily inherit the same PATH value as you see in your Terminal, unless you launch it from the Terminal with an open command.

Two other things pop out at me here: GCC 4.0 is the C compiler, but g++ 4.2 is the C++ compiler. Why are those different?

Also, CMAKE_MAKE_PROGRAM points to /opt/local/bin/gmake. Is that true in both of your build trees? (The command line one and the GUI one?) It seems curious to me that CMake would pick up the C and C++ compilers from /usr/bin, but gmake from /opt/local/bin...

Is your command line environment carefully set up to use exactly these tools from these paths? Or is this also unexpected to you?

You don't mention what version of the Xcode tools you are using at all. Perhaps adding that to your question will help a better answer pop into someone's brain.

One last observation: you have a lot of stuff in your PATH. Minimizing the PATH value you use in your build environments will go a long way to helping you avoid problems like this. I heartily recommend stripping that down to the bare minimum you need, at least for a software building environment.

Sorry for the non-answer answer, but this much commentary seemed a bit excessive for a Stack Overflow comment... :-)

查看更多
登录 后发表回答