3

我正在尝试编译一个 Python 包,其中包含一些 Cython 生成的 C 代码,我遇到了:

gcc: error: x86_64: No such file or directory

这表明 gcc 编译器太新,因此不再支持 -arch 了。我尝试CC=/usr/bin/gcc在 之前进行设置python setup.py install,这适用于主编译命令,但不适用于创建共享对象库的命令:

% setenv CC /usr/bin/gcc
% python setup.py install
running install
running build
running build_py
running build_ext
skipping 'hyperion/util/integrate_core.c' Cython extension (up-to-date)
building 'hyperion.util.integrate_core' extension
/usr/bin/gcc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -DNDEBUG -g -O3 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -I/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/numpy/core/include -I/Library/Frameworks/EPD64.framework/Versions/7.2/include/python2.7 -c hyperion/util/integrate_core.c -o build/temp.macosx-10.5-x86_64-2.7/hyperion/util/integrate_core.o
gcc -bundle -undefined dynamic_lookup -g -arch x86_64 -arch x86_64 build/temp.macosx-10.5-x86_64-2.7/hyperion/util/integrate_core.o -o build/lib.macosx-10.5-x86_64-2.7/hyperion/util/integrate_core.so

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

有没有办法指定用于链接的编译器的绝对路径?

4

2 回答 2

1

使用LDSHARED变量:LDSHARED='/usr/bin/gcc -shared'.

它被埋在sysconfig模块中。尝试这个:

>>> from sysconfig import get_config_vars
>>> get_config_vars('CC', 'CXX', 'LDSHARED')
于 2013-10-17T23:17:41.497 回答
0

我已经这样做了:

CXX="/Developer/usr/bin/g++-4.0" CC="/Developer/usr/bin/gcc-4.0" python setup.py build

但我不确定这是“正确的”;它只是安装 scipy/numpy 时需要使用的长命令的一部分。

(我最终使用的完整命令是 LD_LIBRARY_PATH=/Developer/SDKs/MacOSX10.6.sdk/usr/lib/ FFLAGS="-m64" CFLAGS="-arch x86_64 -I/Developer/SDKs/MacOSX10.6.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/ -I/usr/local/include/freetype2 -I/usr/X11/include -L/usr/X11/lib" LDFLAGS="-Wall -undefined dynamic_lookup -bundle -lpng -arch x86_64" CXX="/Developer/usr/bin/g++-4.0" CC="/Developer/usr/bin/gcc-4.0" python setup.py build

于 2012-05-08T14:22:55.830 回答