Distutils - How to disable, including debugging symbols when creating an extension

I wrote a boost-python extension that is currently being built through distutils.

Unfortunately, I could not find a way, within distutils, to build the extension without debugging symbols or to leave the characters removed from the extension after installation.
Note: I do not pass -debug or -g to create a distutils command (e.g. python setup.py build), and my compiler is gcc on Linux.

Fixed setup.py:

from distutils.core import setup from distutils.extension import Extension setup(name="myPy", ext_modules = [ Extension("MyPyExt", ["MyPyExt.cpp"], libraries = ["boost_python"]) ]) 
+4
source share
2 answers

I found a way, but a little hacked:

 from distutils import sysconfig from distutils.core import setup import platform if platform.system() != 'Windows': # When compilinig con visual no -g is added to params cflags = sysconfig.get_config_var('CFLAGS') opt = sysconfig.get_config_var('OPT') sysconfig._config_vars['CFLAGS'] = cflags.replace(' -g ', ' ') sysconfig._config_vars['OPT'] = opt.replace(' -g ', ' ') if platform.system() == 'Linux': # In macos there seems not to be -g in LDSHARED ldshared = sysconfig.get_config_var('LDSHARED') sysconfig._config_vars['LDSHARED'] = ldshared.replace(' -g ', ' ') setup(...) 
+2
source

You can use the extra_compile_args option to pass arguments to the compiler that are added last and thus have the highest priority. Thus, if you include -g0 (without debugging characters) in extra_compile_args , this overrides the -g value set by Distutils / Setuptools. In your example:

 from distutils.core import setup from distutils.extension import Extension setup( name="myPy", ext_modules = [Extension( "MyPyExt", ["MyPyExt.cpp"], libraries = ["boost_python"], extra_compile_args = ["-g0"] )] ) 

See also: How can I override the compiler flags (gcc) that setup.py uses by default?

+5
source

Source: https://habr.com/ru/post/1443038/


All Articles