整理gcc使用的Cython构建标记 [英] Tidying Up the Cython Build-Flags used by gcc

查看:65
本文介绍了整理gcc使用的Cython构建标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用'setuptools'在Linux上使用gcc自动cythonize和编译我的Cython模块.从现在开始,我需要对提供给gcc的构建标志进行更多控制.如果我在 setup.py 中使用以下内容:

I currently use 'setuptools' to automatically cythonize and compile my Cython modules on Linux using gcc. From now on, I need more control over the build flags supplied to gcc. If I use the following in my setup.py:

cythonize(
    [Extension("*", ["project/*.pyx"])
    nthreads=4
)

我得到的构建标志如下:

I get build flags, that look like:

gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -fPIC -I./fastmat/core -I/home/seb/.local/lib/python3.6/site-packages/numpy/core/include -Iproject/core -Ifastmat/inspect -Iutil -I/usr/include/python3.6m -c project/BlockDiag.c -o build/temp.linux-x86_64-3.6/project/BlockDiag.o

在这里,我对所有的构建标志多次出现而没有以任何(对我来说很明显)的方式发布这个事实感到非常震惊.

Here I am totally flabbergasted by the fact that several build flags occur multiple times and without issuing this in any (to me obvious) way.

如何清理这些构建标记,使它们看起来像建议的

How can I clean up these build flags, such that they look like the ones suggested here? I hope to learn something about setuptools along the way to ultimately get full control over the build process without having to use a self-maintained makefile.

推荐答案

GCC获得的标志来自env变量之一.输入

The flags GCC gets come from one of the env variables. Enter

$ python -c "from distutils import sysconfig;\
print(sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',\
'BASECFLAGS', 'LDFLAGS', 'CCSHARED', 'LDSHARED', 'SO'))"

打印它们.这是 distutils 在默认情况下用于扩展编译的内容.现在检查哪个env var引入了哪个标志,并相应地覆盖env var,例如

to print them. This is what distutils uses by default for extension compilation. Now check which env var introduces which flag and override the env vars accordingly, for example

$ CC="gcc-7.3.0" CFLAGS="-Ofast" python setup.py build_ext

使用特定的编译器版本并启用 O3 优化.

to use the specific compiler version and turn on O3 optimizations.

此外,您似乎正在使用 numpy.distutils 而不是原始的 distutils ,因此请注意额外的include/link标志 numpy 在引擎盖下添加.

Also, it looks like you're using numpy.distutils instead of vanilla distutils, so be aware of extra include/link flags numpy adds under the hood.

这篇关于整理gcc使用的Cython构建标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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