强制setup.py使用我的自定义编译器 [英] Force setup.py to use my custom compiler

查看:302
本文介绍了强制setup.py使用我的自定义编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取setup.py以使用gcc的macports版本编译c ++代码.问题是我要构建的代码不支持Mac的默认clang,这是较新的osx版本的默认gcc.

I'm trying to get setup.py to compile c++ code with the macports version of gcc. The problem is the code I am trying to build, doesn't support mac's default clang, which is the default gcc on newer osx versions.

我创建了一个自定义setup.cfg文件

I created a custom setup.cfg file

setup.cfg

setup.cfg

[build_ext] 
compiler=gcc-mp-4.8

但是,当我运行python setup.py build_ext时,出现以下错误

However when I run python setup.py build_ext I get the following error

运行build_ext

running build_ext

error: don't know how to compile C/C++ code on platform 'posix' with 'gcc-mp-4.8' compiler

如何获取setup.py以使用我的gcc gcc-mp-4.8版本?

How can I get setup.py to use my version of gcc gcc-mp-4.8?

当前setup.py默认使用/usr/bin/clang,当我键入gcc -v时,它表明它正在使用gcc版本4.8.2

Currently setup.py defaults to using /usr/bin/clang, when i type gcc -v it shows that it is using gcc version 4.8.2

推荐答案

--compiler选项期望从我的"unix","msvc","cygwin","mingw32","bcpp"或"emx"理解.您可以尝试通过指定CC环境变量来设置编译器名称.

The --compiler option expects "unix", "msvc", "cygwin", "mingw32", "bcpp", or "emx", from my understanding. You can try setting the compiler name by specifying a CC environment variable instead.

内部setup.py尝试设置os.environ:

os.environ["CC"] = "gcc-4.8"
os.environ["CXX"] = "gcc-4.8"

或者只是:

CC=gcc

g++也将像这样使用;

os.environ["CXX"] = "g++-4.7"

这篇关于强制setup.py使用我的自定义编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆