如何告诉distutils使用gcc? [英] How to tell distutils to use gcc?

查看:230
本文介绍了如何告诉distutils使用gcc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Cython包装一个包含C ++和OpenMP代码的测试项目,并通过 setup.py 文件用distutils构建它。我的文件内容如下:

 从distutils.core导入安装
从distutils.extension import Extension
来自Cython.Build import cythonize
来自Cython.Distutils import build_ext


modules = [Extension(Interface,
[Interface.pyx ,Parallel.cpp],
language =c ++,
extra_compile_args = [ - fopenmp],
extra_link_args = [ - fopenmp])]
b $ b for e in modules:
e.cython_directives = {embedsignature:True}

setup(name =Interface,
cmdclass = {build_ext: build_ext},
ext_modules = modules)

-fopenmp 标志与gcc一起使用来编译和链接到OpenMP。但是,如果我只是调用

  cls〜/ workspace / CythonOpenMP / src $ python3 setup.py build 

此标记无法识别,因为编译器是clang:

 运行build 
运行build_ext
跳过'Interface.cpp'Cython扩展(最新)
构建'接口'扩展
-Wno-unused-result -fno-common -dynamic -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I / usr / local / include -I / usr / local / opt / sqlite / include -I / usr / local /Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/include/python3.3m -c Interface.cpp -o build / temp.macosx-10.8-x86_64-3.3 / Interface.o -fopenmp
clang:warning:编译期间未使用的参数:'-fopenmp'
cc -Wno-unused-result -fno-common -dynamic -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I / usr / local / include -I / usr / local / opt / sqlite / include -I / usr / local / Cellar / python3 / 3.3.0 / Frameworks / Python.framework / Versions / 3.3 / include / python3.3m -c Parallel.cpp - o build / temp.macosx-10.8-x86_64-3.3 / Parallel.o -fopenmp
clang:warning:参数在编译期间未使用:'-fopenmp'
Parallel.cpp:24:10:warning:unknown pragma ignored [-Wunknown-pragmas]
#pragma omp parallel for
^
1生成警告。
c ++ -bundle -undefined dynamic_lookup -L / usr / local / lib -L ​​/ usr / local / opt / sqlite / lib build / temp.macosx-10.8-x86_64-3.3 / Interface.o build / temp.macosx -10.8-x86_64-3.3 / Parallel.o -o build / lib.macosx-10.8-x86_64-3.3 / Interface.so -fopenmp
ld:没有为-lgomp
找到库clang:error:linker命令失败,退出代码1(使用-v查看调用)
错误:命令'c ++'失败退出状态1

我已经失败地尝试指定gcc:

  cls〜/ workspace / CythonOpenMP / src $ python3 setup.py build --compiler = g ++  -  4.7 
运行build
运行build_ext
错误:不知道如何在平台'posix'上编译C / C ++代码'g ++ - 4.7'编译器

如何告诉distutils使用gcc?

$

$

I want to wrap a test project containing C++ and OpenMP code with Cython, and build it with distutils via a setup.py file. The content of my file looks like this:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext


modules = [Extension("Interface",
                     ["Interface.pyx", "Parallel.cpp"],
                     language = "c++",
                     extra_compile_args=["-fopenmp"],
                     extra_link_args=["-fopenmp"])]

for e in modules:
    e.cython_directives = {"embedsignature" : True}

setup(name="Interface",
     cmdclass={"build_ext": build_ext},
     ext_modules=modules)

The -fopenmp flag is used with gcc to compile and link against OpenMP. However, if I just invoke

cls ~/workspace/CythonOpenMP/src $ python3 setup.py build

this flag is not recognized, because the compiler is clang:

running build
running build_ext
skipping 'Interface.cpp' Cython extension (up-to-date)
building 'Interface' extension
cc -Wno-unused-result -fno-common -dynamic -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/include/python3.3m -c Interface.cpp -o build/temp.macosx-10.8-x86_64-3.3/Interface.o -fopenmp
clang: warning: argument unused during compilation: '-fopenmp'
cc -Wno-unused-result -fno-common -dynamic -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/include/python3.3m -c Parallel.cpp -o build/temp.macosx-10.8-x86_64-3.3/Parallel.o -fopenmp
clang: warning: argument unused during compilation: '-fopenmp'
Parallel.cpp:24:10: warning: unknown pragma ignored [-Wunknown-pragmas]
        #pragma omp parallel for
                ^
1 warning generated.
c++ -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.8-x86_64-3.3/Interface.o build/temp.macosx-10.8-x86_64-3.3/Parallel.o -o build/lib.macosx-10.8-x86_64-3.3/Interface.so -fopenmp
ld: library not found for -lgomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'c++' failed with exit status 1

I've unsucessfully tried to specify gcc:

cls ~/workspace/CythonOpenMP/src $ python3 setup.py build --compiler=g++-4.7
running build
running build_ext
error: don't know how to compile C/C++ code on platform 'posix' with 'g++-4.7' compiler

How can I tell distutils to use gcc?

解决方案

Try setting the "CC" environment variable from inside the setup.py with os.environ.

这篇关于如何告诉distutils使用gcc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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