How may I override the compiler (GCC) flags that setup.py uses by default?
Prepend
CFLAGS="-O0"
before you runsetup.py
:
The% CFLAGS="-O0" python ./setup.py
-O0
will be appended toCFLAGS
while compiling, therefore will override previous-O2
setting.Another way is add
-O0
toextra_compile_args
insetup.py
:moduleA = Extension('moduleA', .....,
include_dirs = ['/usr/include', '/usr/local/include'],
extra_compile_args = ["-O0"],
)If you want to remove all default flags, use:
% OPT="" python ./setup.py
How does one overwrite the default compile flags for Cython when building with distutils?
larsmans comment was right - using /usr/bin/cython addresses my issue.
Distutils compiler options configuration
I actually export them to the environment, just like for autotools' configure:
export CC=/usr/local/bin/clang
export CFLAGS=-I${HOME}/include
export LDFLAGS=-lboost
If you also need to override the linker separately:export LDSHARED=/usr/local/bin/clang -shared
And if you don't like export
ing the settings to your environment, do something like this for a one-time setting:CC=/usr/local/bin/clang CFLAGS=-I${HOME}/include python setup.py build
If you want to find out what the default options were when python was build, use python-config --<flag>
. Some flags are cflags
, ldflags
, libs
or includes
. How to override -DNDEBUG compile flag when building a Cython module
You can manually undefine NDEBUG
, if it is defined, prior to including <cassert>
. Add the following lines to the top of the cpp file which contains these assert statements. Make sure these are the very first statements in that file.
#ifdef NDEBUG
# define NDEBUG_DISABLED
# undef NDEBUG
#endif
#include <cassert>
#ifdef NDEBUG_DISABLED
# define NDEBUG // re-enable NDEBUG if it was originally enabled
#endif
// rest of the file
This will ensure that NDEBUG
is not defined when the processor includes <cassert>
, which will result in the assertion checks being compiled into your code. Possible to change distutils default compiler options?
The option is in distutils/cygwinccompiler.py. If you can edit the file in the Python installation just remove it.
Related Topics
Does Python Evaluate If's Conditions Lazily
Extract Int from String in Pandas
How to Include Image Files in Django Templates
How to Modify Procfile to Run Gunicorn Process in a Non-Standard Folder on Heroku
How to Convert a Python List into a C Array by Using Ctypes
Python Tracing a Segmentation Fault
How to Set Opacity of Background Colour of Graph with Matplotlib
Is There a Simple Process-Based Parallel Map for Python
Python Element-Wise Tuple Operations Like Sum
Is There a Function to Determine Which Quarter of the Year a Date Is In
Pip Is Not Able to Install Packages Correctly: Permission Denied Error
How to Check Task Status in Celery