For my python extension, I have both C (from the built-in library) and C ++ files, and they are compiled and linked to each other. Only part of C ++ interacts with Python (via SWIG). This works both on windows with VS2015, and gcc under linux. However, using gcc for C ++ files requires a different set of compiler flags (for example, -std = C ++ 11, -Wno-reorder) than C files to avoid warnings about incorrect flags in C.
Is there a setuptools / distutils way to change compiler flags for each file separately, for example. based on file extension?
I am already using a custom build step from https://stackoverflow.com/a/4646268/220 .
Update:
The main problem is that it distutils.ccompiler
does not check the file extension for C or C ++ and runs everything with $ CC. Even the definition of CXXFLAGS does not help. I set warnings not using export
, and not using the definition os.eniviron
in the setup.py file.
Update 2:
On macOS with CLang 8.0.0, things get worse: trying to compile a .c file with -std = C ++ 11 is not a warning, but an error.
source
share