2

I want to compile my python project with cython. I created this setup.py file :

from setuptools import setup, find_packages
from Cython.Build import cythonize

recursive_tree = [file for file in glob.iglob("sample/**/*.py",  recursive=True)]

setup(
    name                                     = 'sample',
    version                                  = sample.__version__,
    packages                                 = find_packages(),
    author                                   = "42",
    description                              = "Cython Sample",
    include_package_data                     = True,
    ext_modules                              = cythonize(
        recursive_tree,
        nthreads=2,
        exclude="setup.py",
        build_dir = "out",
    ),
)

In this thread, we can see it's possible to add some extra compile args, but can we do the opposite and remove one?

When I use this command : python setup.py build_ext --inplace I got this gcc configuration :

gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python3.6m -c out/sample/hello.c -o build/temp.linux-x86_64-3.6/out/sample/hello.o

gcc -pthread -shared build/temp.linux-x86_64-3.6/out/sample/hello.o -o build/lib.linux-x86_64-3.6/hello.cpython-36m-x86_64-linux-gnu.so

How can i remove the -g option?

Community
  • 1
  • 1
Jguillot
  • 214
  • 3
  • 14

1 Answers1

3

With reference to similar this question: How may I override the compiler (gcc) flags that setup.py uses by default? (which I don't think it quite a duplicate). They solve a similar problem by adding extra command line arguments to undo the ones that setup.py adds by default.

In this case -g0 "negates -g". Therefore add -g0 to extra_compile_args

setup(... # everything as before
      extra_compile_args = ['-g0'])
Community
  • 1
  • 1
DavidW
  • 29,336
  • 6
  • 55
  • 86
  • Get a warning when i'm using `extra_compile_args` in `setup()` and with cythonize. I had a good result with using `moduleA = Extension('moduleName', [fileToCompile], extra_compile_args=[-g0])` – Jguillot Feb 02 '17 at 13:41