For my python extension, I have both C (from an embedded library) and C++ files and they are compiled and linked together. Only the C++ part interfaces with Python (via SWIG). This works both in windows with VS2015 and gcc under linux. However, with gcc, the C++ files need a different set of compiler flags (eg. -std=c++11, -Wno-reorder) than the C files, to avoid warnings concerning the improper flags in C.
Is there a way in setuptools / distutils to change compiler flags for each file seperatly, eg. based on the file extension?
I use already a custom build step from https://stackoverflow.com/a/36293331/3032680.
Update:
The main problem is, that distutils.ccompiler
does not check the file extension for C or C++ and is running everything with $CC. Even defining CXXFLAGS does not help. I will stand the warnings, neither with export
nor a definition using os.eniviron
in the setup.py file.
Update 2:
On macOS with CLang 8.0.0 the situation gets worse: Trying to compile a .c file with -std=c++11 is not a warning but an error.