I've written a boost-python extension that currently is being built via distutils.
Unfortunately I have been unable to find a way, within distutils, to build the extension without debug symbols or have the symbols stripped from the extension upon installation.
Note: I am not passing --debug or -g to build command of distutils (e.g., python setup.py build), and my compiler is gcc on Linux.
Exampled setup.py:
from distutils.core import setup
from distutils.extension import Extension
setup(name="myPy",
ext_modules = [
Extension("MyPyExt", ["MyPyExt.cpp"],
libraries = ["boost_python"])
])
You can use the option extra_compile_args
to pass arguments to the compiler which are appended last and thus have highest priority. Thus, if you include -g0
(no debug symbols) in extra_compile_args
, this overrides the -g
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 may I override the compiler (gcc) flags that setup.py uses by default?
I've found a way but is a bit hacky:
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(...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With