【问题标题】:Compilation error when using gcc in OSX 10.10.5在 OSX 10.10.5 中使用 gcc 时出现编译错误
【发布时间】:2015-12-27 02:25:18
【问题描述】:

我正在尝试使用 python setup.py install 安装 python 包,但在安装过程的某些时候出现错误:

gcc: error: x86_64: No such file or directory
gcc: error: unrecognized option ‘-arch’
error: command 'gcc' failed with exit status 1

以前,我为 Xcode 7 安装了 Xcode 7.0 和它们各自的命令行工具。编译器似乎在 which gcc 本地 /usr/local/bin/gcc。但是,当我尝试gcc -v 时,我得到了Segmentation fault: 11。此外,当我尝试/usr/bin/gcc -v 时,我得到了

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin14.5.0
Thread model: posix

然后,安装的编译器似乎位于不同的位置。 Command line tool installed, but gcc/g++ compiler not working 中提出了类似的问题,但没有明确的解决方案。您知道如何修复它(链接到实际安装的编译器以继续安装 Python 包)?提前致谢。

【问题讨论】:

  • 您可能想看看设置了哪些环境变量会影响路径或编译器操作。
  • 如果安装了 Xcode 命令行工具(它们安装在 /usr/bin 中),则不需要 --prefix。使用xcode-select --install
  • 当我输入 xcode-select --install 这就是我得到的 xcode-select: error: command line tools are already installed, use "Software Update" to install updates @Droppy
  • OK 删除--prefix 并使用CC=clang ./configure <other-options>
  • @Droppy 我需要修改哪个文件?

标签: python macos gcc osx-yosemite


【解决方案1】:

扩展@Droppy 的评论:xcode 没有在 /usr/local/bin 中安装 gcc(OP 没有说明它的来源)。 MacPorts 会将其放在 /opt/local/bin/gcc 中,但不会选择当前端口。所以CC=clang是最简单的回答方式。但是,OP 正在询问如何在 setup.py 中覆盖它。

已在这些问题中讨论过:

first 是最中肯的,导致这个建议:

CC=/usr/bin/clang CFLAGS="-O" python setup.py build

(clang 只是忽略了大多数 gcc 选项,甚至没有给出警告,但设置 CFLAGS 可以帮助说服 python 脚本不要尝试 clang 不太可能支持的选项)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-30
    相关资源
    最近更新 更多