How to tell distutils to use gcc?
Try setting the "CC" environment variable from inside the setup.py with os.environ.
How to override python's distutils gcc linker with icc?
You need to override the linker
by setting export LDSHARED="icc -shared". That generates the icc linker. Here is an example of the build log by typing
CC=icc python3.4 setup.py build_ext
Alternatively you can also do the same by typing
LDSHARED="icc -shared" CC=icc python3.4 setup.py build_ex
icc -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.4m -c /home/a/libPython/Cython-0.24/Cython/Plex/Scanners.c -o build/temp.linux-x86_64-3.4/home/a/libPython/Cython-0.24/Cython/Plex/Scanners.o
icc: command line warning #10006: ignoring unknown option '-fwrapv'
creating build/lib.linux-x86_64-3.4
creating build/lib.linux-x86_64-3.4/Cython
creating build/lib.linux-x86_64-3.4/Cython/Plex
icc -shared -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.4/home/a/libPython/Cython-0.24/Cython/Plex/Scanners.o -o build/lib.linux-x86_64-3.4/Cython/Plex/Scanners.cpython-34m.so
cythoning /home/a/libPython/Cython-0.24/Cython/Plex/Actions.py to /home/a/libPython/Cython-0.24/Cython/Plex/Actions.c
How to specify C++11 with distutils?
You can use the extra_compile_args
parameter of distutils.core.Extension
:
ext = Extension('foo', sources=[....],
libraries=[....],
extra_compile_args=['-std=c++11'],
....)
Note that this is completely platform dependent. It won't even work on some older versions of gcc and clang.
How to pass flag to gcc in Python setup.py script?
Maybe you need to set extra_link_args
, too? extra_compile_args
is used when compiling the source code, extra_link_args
when linking the result.
Get the commands distutils passes to the compiler
It's not as simple as a set of options but you can see how it works. In your python source directory look for this
distutils/ccompiler.py
In that file each compiler has an entry like this
# Map compiler types to (module_name, class_name) pairs -- ie. where to
# find the code that implements an interface to this compiler. (The module
# is assumed to be in the 'distutils' package.)
compiler_class = { 'unix': ('unixccompiler', 'UnixCCompiler',
"standard UNIX-style compiler"),
'msvc': ('msvccompiler', 'MSVCCompiler',
"Microsoft Visual C++"),
'cygwin': ('cygwinccompiler', 'CygwinCCompiler',
"Cygwin port of GNU C Compiler for Win32"),
'mingw32': ('cygwinccompiler', 'Mingw32CCompiler',
"Mingw32 port of GNU C Compiler for Win32"),
'bcpp': ('bcppcompiler', 'BCPPCompiler',
"Borland C++ Compiler"),
'emx': ('emxccompiler', 'EMXCCompiler',
"EMX port of GNU C Compiler for OS/2"),
}
You can find the code you're looking for in
distutils/cygwinccompiler.py
If you edit your setup.py script and add this
from distutils.core import setup,Extension
from distutils.cygwinccompiler import Mingw32CCompiler
from pprint import pprint
module1 = Extension('demo', sources = ['demo.c'])
m32 = Mingw32CCompiler()
pprint (vars(m32))
setup (name = 'PackageName',
version = '1.0',
description = 'This is a demo package',
ext_modules = [module1])
You can see quite a few of the options available...
{'archiver': ['ar', '-cr'],
'compiler': ['gcc', '-O', '-Wall'],
'compiler_cxx': ['g++', '-O', '-Wall'],
'compiler_so': ['gcc', '-mdll', '-O', '-Wall'],
'dll_libraries': None,
'dllwrap_version': None,
'dry_run': 0,
'force': 0,
'gcc_version': LooseVersion ('4.2.1'),
'include_dirs': [],
'ld_version': None,
'libraries': [],
'library_dirs': [],
'linker_dll': 'dllwrap',
'linker_exe': ['gcc'],
'linker_so': ['dllwrap', '-mdll', '-static'],
'macros': [],
'objects': [],
'output_dir': None,
'preprocessor': None,
'ranlib': ['ranlib'],
'runtime_library_dirs': [],
'verbose': 0}
To access individual options you can use them as follows...
print m32.compile
['gcc', '-O', '-Wall']
There's no simple set of flags. A lot of the flags are configured at runtime and the code above shows you were to look to see how they're generated etc.
Related Topics
Appending Item to Lists Within a List Comprehension
Sphinx's Autodoc's Automodule Having Apparently No Effect
Rolling Mean on Pandas on a Specific Column
Read from File After Write, Before Closing
How to Fix the "Element Not Interactable" Exception
Python Mixed Integer Linear Programming
Differencebetween I = I + 1 and I += 1 in a 'For' Loop
How to Form Tuple Column from Two Columns in Pandas
Example of the Right Way to Use Qthread in Pyqt
Comparing Numpy Arrays Containing Nan
Class Inheritance in Python 3.7 Dataclasses