Python distutils gcc 路径
我正在尝试交叉编译pycrypto这个包,离成功越来越近了,但我遇到了一个问题,搞不明白。
我希望distutils使用特定的交叉编译gcc,所以我设置了CC这个环境变量,似乎在第一次调用编译器时能识别这个设置,但之后就不行了。
export CC="/opt/teeos/buildroot/output/host/usr/bin/i586-linux-gcc"
/opt/teeos/buildroot/output/host/usr/bin/i586-linux-gcc -fno-strict-aliasing -fwrapv -Wall -Wstrict-prototypes -fPIC -std=c99 --sysroot=/opt/teeos/buildroot/output/staging -I/opt/teeos/buildroot/output/staging/usr/include/python2.7 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/python2.7 -c src/_fastmath.c -o build/temp.linux-i686-2.7/src/_fastmath.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions build/temp.linux-i686-2.7/src/_fastmath.o -lgmp -o build/lib.linux-i686-2.7/Crypto/PublicKey/_fastmath.so
unable to execute gcc: No such file or directory
为了测试,我暂时把系统的gcc移动了,让它找不到。
我该如何让distutils在每次调用编译器时都能识别CC=/opt/buildroot...
这个选项,或者设置我想让distutils使用的GCC和LD的路径呢?
1 个回答
16
这听起来和我最近给的另一个回答有点像,关于自定义distutils编译器的内容。你还需要定义一下LDSHARED
,这是用来生成最终共享对象的命令。看看这样是否有效:
>>> from distutils import sysconfig
>>> sysconfig.get_config_var('LDSHARED')
'gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
>>> sysconfig.get_config_var('CC')
'gcc -pthread'
然后在CC
和LDSHARED
这两个环境变量中,把gcc
替换成你想要的编译器和选项:
% LDSHARED="i586-linux-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions" \
CC="i586-linux-gcc -pthread" python setup.py build