Skip to content Skip to sidebar Skip to footer

Tidying Up The Cython Build-flags Used By Gcc

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

Solution 1:

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'))"

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

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

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.

Post a Comment for "Tidying Up The Cython Build-flags Used By Gcc"