Using different compiler flags for C and C ++ files in python extension

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.ccompilerdoes 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.enivironin 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.

+4
source share
2 answers

Extension has a parameter extra_compile_args- a list of lines passed to the compiler.

See also Fine tune compiler / linker flags using a file Setup.

0
source

distutils , .c .cpp. , CFLAGS CXXFLAGS , gcc CLang - -. Visual Studio ++.

, , C ++ C-Source .cpp, C. , gcc CLang - , C ++.

, , - C- distutlis Python .

0

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


All Articles