How to override default compiler option ?

3,213 views
Skip to first unread message

tundra

unread,
May 27, 2010, 1:19:46 AM5/27/10
to cython-users
When I run
python setup.py build_ext --inplace
GCC is always invoked with default options
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -
Wstrict-prototypes -fPIC

Actually I need to debug generated C code. To do this I have to
disable optimization option. ("-O2"). But I cannot find file where
these default options are specified.
How to get around it ?

My system:
uname -a
Linux 2.6.32-22-generic #33-Ubuntu SMP Wed Apr 28 13:28:05 UTC 2010
x86_64 GNU/Linux
gcc --version
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
python --version
Python 2.6.5
cython --version
Cython version 0.11.2


Robert Bradshaw

unread,
May 27, 2010, 1:47:17 AM5/27/10
to cython...@googlegroups.com
On May 26, 2010, at 10:19 PM, tundra wrote:

> When I run
> python setup.py build_ext --inplace
> GCC is always invoked with default options
> gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -
> Wstrict-prototypes -fPIC
>
> Actually I need to debug generated C code. To do this I have to
> disable optimization option. ("-O2"). But I cannot find file where
> these default options are specified.
> How to get around it ?

You specify this with

Extension(..., extra_compile_args=["-O0"])

which should happen after (and override) the -O2 option. Setting the
CFLAGS environment variable may work as well, but I'm not sure.

- Robert

Stefan Behnel

unread,
May 27, 2010, 2:06:29 AM5/27/10
to cython...@googlegroups.com
Robert Bradshaw, 27.05.2010 07:47:

> On May 26, 2010, at 10:19 PM, tundra wrote:
>> When I run
>> python setup.py build_ext --inplace
>> GCC is always invoked with default options
>> gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -
>> Wstrict-prototypes -fPIC

Those are the CFLAGS that were used by the build of your CPython
interpreter, it remembers them for later extension builds.


>> Actually I need to debug generated C code. To do this I have to
>> disable optimization option. ("-O2"). But I cannot find file where
>> these default options are specified.
>> How to get around it ?
>
> You specify this with
>
> Extension(..., extra_compile_args=["-O0"])
>
> which should happen after (and override) the -O2 option. Setting the
> CFLAGS environment variable may work as well, but I'm not sure.

Yes, CFLAGS are appended after the default configuration.

Stefan

Sébastien Giguère

unread,
May 29, 2010, 10:16:59 AM5/29/10
to cython-users
Any one tried compiling with -O3 instead of default -O2? I'm wondering
if theire could be some performance gain from it.

Robert Bradshaw

unread,
May 29, 2010, 1:22:54 PM5/29/10
to cython...@googlegroups.com
On May 29, 2010, at 7:16 AM, Sébastien Giguère wrote:

> Any one tried compiling with -O3 instead of default -O2? I'm wondering
> if theire could be some performance gain from it.

I usually compile with -O3. Distutils uses whatever the Python library
was compiled with, and that's the default we use for Sage.

- Robert

Reply all
Reply to author
Forward
0 new messages