【问题标题】:Broken CMake and GCC under OS XOS X 下损坏的 CMake 和 GCC
【发布时间】:2013-05-09 15:49:41
【问题描述】:

在我的 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.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>

通过查看 Internet 上的论坛等,我确定这可能与我的 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

但是,在使用某些库时编译并不总是成功 - 参见例如 this question I have asked here。因此,我认为cmake 进程中可能仍有问题。

【问题讨论】:

  • 编译测试失败的输出可能是该日志中最有用的信息。
  • 谢谢,我已经包含了完整的 CMake 输出。看起来目标文件的创建可能无法正常工作?
  • 然后检查你的 binutils 安装
  • 这是什么 OSX 和 XCode 版本? /usr/bin/gcc-4.0 -isysroot -o CMakeFiles/cmTryCompileExec.dir/testCCompiler.co -c /Users/bill/Desktop/cmake_test/build/CMakeFiles/CMakeTmp/testCCompiler.c 实际上给出了什么?
  • 请考虑您使用的 GCC 版本 4.0,已有 8 年历史(2005 年)。检查您使用的库是否与该版本兼容。考虑将编译器升级到 GCC 4.8 或 Clang 3.3。

标签: c gcc cmake


【解决方案1】:

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

就 CMake 版本而言,您使用的是相当旧的 CMake 2.8.2。尝试使用 2.8.11 或即将发布的 2.8.12 的候选版本,看看问题是否仍然存在。如果不出意外,也许您会收到更好的错误消息。

查看此问题和答案及其链接,了解在 Mac 上通过其他方式启动的命令行环境和 GUI 应用程序之间保证 PATH 值一致的各种方法:How do I set the global PATH environment variable on OS X?

CMake GUI 不一定继承与您在终端中看到的相同的 PATH 值,除非您使用打开命令从终端启动它。

这里突然出现了另外两件事: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 值将大大有助于避免此类问题。我衷心建议将其剥离到您需要的最低限度,至少对于软件构建环境而言。

很抱歉没有回答,但对于 StackOverflow 评论来说,这么多评论似乎有点过分...... :-)

【讨论】:

  • 感谢您的详细回答!你添加了很多细节和知识。我认为最终我的系统很糟糕,我已经完成了完整的系统重新安装,这有助于理顺很多事情!
【解决方案2】:

我也遇到过这个问题,我已经通过设置正确的CXXFLAGSCPPFLAGS 解决了这个问题。我想你也应该检查一下。

一个简单的解决方案是:

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

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

【讨论】:

    猜你喜欢
    • 2011-04-08
    • 1970-01-01
    • 2014-02-04
    • 2015-11-25
    • 1970-01-01
    • 1970-01-01
    • 2013-05-11
    • 2010-09-11
    • 1970-01-01
    相关资源
    最近更新 更多