0

When pip-installing a Python project with C++ parts,

pip3 install . --verbose --user

the typical compile line will be something like

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/eigen3/ -I/usr/local/include/python3.7 -I/home/nschloe/.local/include/python3.7m -I/usr/include/python3.7m -c src/generate.cpp -o build/temp.linux-x86_64-3.7/src/generate.o

Explicitly setting CFLAGS like

OPT="" CFLAGS="" pip3 install . --verbose --user

results in

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/eigen3/ -I/usr/local/include/python3.7 -I/home/nschloe/.local/include/python3.7m -I/usr/include/python3.7m -c src/generate.cpp -o build/temp.linux-x86_64-3.7/src/generate.o

retaining most of the flags.

Question: Where are all the compiler options set? More specifically: How can I remove -g? (It's eating too much memory.)

Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
  • 1
    Possible duplicate of [How may I override the compiler (gcc) flags that setup.py uses by default?](https://stackoverflow.com/questions/6928110/how-may-i-override-the-compiler-gcc-flags-that-setup-py-uses-by-default) – ivan_pozdeev Apr 22 '19 at 22:47
  • from a comment by [bwarren2](https://stackoverflow.com/users/2188525/bwarren2) in https://stackoverflow.com/q/24763871/6018688 : `export -L and -I calls for CCFLAGS, CFLAGS, and LDFLAGS` – fabianegli Apr 22 '19 at 23:00
  • @ivan_pozdeev @fabianegli None of the suggested solutions removed the `-g` flag. Updated the question accordingly. – Nico Schlömer Apr 23 '19 at 05:53
  • Could you modify `setup.py` and use [sysconfig](https://docs.python.org/3/library/sysconfig.html) to extract and modify the `CFLAGS` var with `compiler_options = sysconfig.get_config_var('CFLAGS').split()` ? Something similar [here](https://pythonextensionpatterns.readthedocs.io/en/latest/compiler_flags.html#setting-flags-automatically-in-setup-py) – Christian May 03 '19 at 06:53

0 Answers0