【问题标题】:Python distutils gcc pathPython distutils gcc 路径
【发布时间】:2011-08-24 13:58:33
【问题描述】:

我正在尝试交叉编译 pycrypto 包,而且我越来越接近,但是我遇到了一个我无法弄清楚的问题。

我希望 distutils 使用交叉编译特定的 gcc- 所以我设置了 CC env var,它似乎尊重编译器第一次调用的设置,但就是这样。

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 的路径?

【问题讨论】:

    标签: python compilation distutils


    【解决方案1】:

    这听起来类似于我最近为customizing the distutils compiler 给出的另一个答案。您还需要定义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'
    

    然后在CCLDSHARED 环境变量中将gcc 替换为您想要的编译器和选项:

    % LDSHARED="i586-linux-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions" \
      CC="i586-linux-gcc -pthread" python setup.py build
    

    【讨论】:

    • 我现在正在重建我的工具链——我一直在搞乱它,想要一个干净的基础;我一完成就试试这个。这看起来很完美!我阅读了 distutils 文档并搜索了所有我能想到的东西——你在哪里找到的?
    • 酷,我希望它有所帮助。我通过挖掘 distutils 的胆量找到了它,我已经多次处理相关问题(自定义编译器选项等)。
    • 做到了...但是现在我的工具链链接到了错误的库。以前从未发生过 - 但那是一个不同的问题。该死的东西。谢谢!
    猜你喜欢
    • 2014-10-15
    • 2014-12-12
    • 1970-01-01
    • 2022-01-21
    • 2011-03-14
    • 1970-01-01
    • 1970-01-01
    • 2014-06-05
    • 1970-01-01
    相关资源
    最近更新 更多