OS X下的CMake和GCC损坏

在我的OS X平台上运行cmake-gui configure ,出现以下错误:

 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.co /usr/bin/gcc-4.0 -isysroot -o CMakeFiles/cmTryCompileExec.dir/testCCompiler.co -c /Users/bill/Desktop/cmake_test/build/CMakeFiles/CMakeTmp/testCCompiler.c i686-apple-darwin10-gcc-4.0.1: CMakeFiles/cmTryCompileExec.dir/testCCompiler.co: No such file or directory  

通过在互联网上查看论坛等,我已经确定这可能与我的PATH变量有关。 这是我的PATH变量用于分析:

 ! 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 

最近,当我配置Python时,这个路径变量已经改变了,我认为GCC问题必须在同一时间出现。 我的系统安装可能出现什么问题?


更多细节。 CMAKE_MAKE_PROGRAM指定的构建程序是/opt/local/bin/gmake

我还发现只有在cmake-gui运行Configure时才会抛出这些错误。 在命令行(从构建文件夹运行cmake .. ),配置完成正常:

 ! 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 

但是,使用某些库时编译并不总是成功 – 例如,请参阅此问题 。 因此,我认为在cmake过程中可能仍会出现问题。

关于您的问题的一些观察,可能会引导您找到解决方案……

你正在使用CMake 2.8.2,这是相当陈旧的,就CMake版本而言。 尝试使用2.8.11或即将发布的2.8.12的候选版本来查看问题是否仍然存在。 如果没有别的,也许你会得到一个更好的错误信息。

请参阅此问题和答案及其链接,以了解在Mac上通过其他方式启动的命令行环境和GUI应用程序之间保证一致PATH值的各种方法: 如何在OS X上设置全局PATH环境变量?

CMake GUI不一定会inheritance您在终端中看到的相同PATH值,除非您使用open命令从终端启动它。

另外还有两件事在我这里:GCC 4.0是C编译器,但g ++ 4.2是C ++编译器。 为什么那些不同?

此外, CMAKE_MAKE_PROGRAM指向/opt/local/bin/gmake 。 这两个构建树都是如此吗? (命令行一和GUI一个?)我觉得CMake会从/usr/bin选择C和C ++编译器,但是来自/opt/local/bin gmake似乎很奇怪……

您的命令行环境是否经过精心设置,以便从这些路径中使用这些工具? 或者这对你来说意外吗?

您没有提到您正在使用的Xcode工具的版本。 也许在您的问题中添加这些内容可以帮助更好地回答流入某人的大脑。

最后一个观察结果:你的PATH中有很多东西。 最大限度地减少在构建环境中使用的PATH值将大大有助于避免这样的问题。 我衷心建议将其剥离到您需要的最低限度,至少对于软件构建环境而言。

对于非答案的答案很抱歉,但是对于Stack Overflow评论来说,这篇评论似乎有些过分…… 🙂

我也遇到过这个问题,我通过设置正确的CXXFLAGSCPPFLAGS修复它。 我想你也应该检查一下。

一个简单的解决方案是:

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

或者你应该检查你的PATH是否正确。 您应该能够在当前shell中找到CXX编译器和C编译器。