[Distutils] Optimization of C++ extensions to Python
michael.wieher at gmail.com
Mon Jun 30 20:02:54 CEST 2008
I tried this question on the C++/Python SIG and was told to ask here. So.
When using distutils to build an extension (shared library), a C++
library to be imported into python, I find the optimization level set
for me, to -O2
This is great, I guess, but for certain debugging tools (valgrind) I
need that to be -O0
I tried setting the extra_compile_args and get output like this
gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic
-fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fPIC
-I/usr/include/python2.4 -c memrid.cpp -o
Which as you can see, has -O2 (the default) following -DNDEBUG ... and
my "extra" argument appended ... as -O0.
I need to be sure that this overrides the -O2 setting (or know how to
set it to -O0 correctly) ...
I noted that the binaries produced are different and that the binary
created when -O0 is in the gcc string is larger than the other...
the GCC documentation I could find didn't address the issue of
multiple flags on the same line and/or how the compiler would handle
them, and I think there is/should be a "correct" way of doing this
such that the confusion of "which optimization level is it using"
a) tell me if my binary compiled w/extra_compile_args -O0 is, indeed, level zero
b) tell me the correct way to adjust this flag?
More information about the Distutils-SIG