问题
I am compiling some cython extensions in linux and noticed that it defaults to using -O2 when building from the distutils mechanism. I was wondering if there was a simple way to change that to a -O3.
I have tried using the extra_compile_args on Extension objects, but that leads to both -O2 and -O3 being passed as arguments to gcc. I kind of want to play with other esoteric gcc options and thus am hoping I can just control the compilation step. An obvious question is "why don't I just run cython my.pyx and compile the results manually?". I would love to, is my answer... but the cython executable in /usr/local/bin/ throws a DistributionNotFound: Cython==0.12.1 error when run from the command line. I haven't quite figured that one out.
Anyway, I am not sure if its a cython thing, a distutils thing or a broken apt package thing. I simply grabbed cython out of the ubuntu 11.10 apt repo (and am currently using ubuntu 11.10).
回答1:
using extra_compile_args=["-O3"] in your setup.py, the "-O3" should appear after the -O2 option overrading it. Check the share object (.so, or .dll) size in order to confirm it quickly.
Davide
回答2:
larsmans comment was right - using /usr/bin/cython addresses my issue.
来源:https://stackoverflow.com/questions/8236648/how-does-one-overwrite-the-default-compile-flags-for-cython-when-building-with-d