【发布时间】:2016-12-22 21:40:30
【问题描述】:
我正在使用 OSX v10.11.6 并安装了最新版本的 xcode。所以我的默认编译器是gcc,实际上是clang。我已经使用 homebrew 安装 gcc5 以便我可以使用 openMP,并且通过在我的 Makefiles 中为我的 C 源代码设置 CC := g++-5,我可以成功编译 C 源代码,并使用非平凡的 -fopenmp。
我想做的是让 Cython 使用 gcc5 进行编译,这样我就可以使用 Cython 的原生 prange 功能,如最小示例 here 中所示。我在this gist 中写了一个最小的例子,从 Neal Hughes 页面借来的。当我尝试使用 setup.py 编译 omp_testing.pyx 时,我收到一个(可能不相关的)警告和致命错误:
cc1plus: warning: command line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++
omp_testing.cpp:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation.
#error Do not use this file, it is the result of a failed Cython compilation.
^
error: command 'g++-5' failed with exit status 1
阅读How to tell distutils to use gcc? 后,我尝试在setup.py 中设置CC 环境变量,但这不起作用。我应该如何修改我的 Cython setup.py 文件以使用 g++-5 进行编译?
【问题讨论】:
-
该错误与 GCC 无关。 Cython 处理步骤失败,留下一个旨在导致编译错误的文件。
-
你能详细说明@DavidW吗?
-
setup.py做了(至少)两件事。它使用 Cython 将您的.pyx文件处理为.c文件,然后它使用您的 C 编译器编译 C 文件。如果 Cython 无法处理.pyx它会产生一些有用的错误输出,告诉你它为什么不开心,它会产生一个omp_testing.c文件,其中包含一个#error行,告诉任何 C 编译器停止。当您运行setup.py时,您应该会看到一些额外的错误消息(前几条通常最有帮助)。如果失败,您可以自己从命令行运行cython omp_testing.pyx以查看问题所在。
标签: python c++ macos gcc cython