How to tell distutils to use gcc?

雨燕双飞 提交于 2019-11-26 19:36:55

Try setting the "CC" environment variable from inside the setup.py with os.environ.

Just in case some others are facing the same problem under Windows (where CC environment variable wouldn't have any effect) :

  • Create file "C:\Python27\Lib\distutils\distutils.cfg" and write this inside :

Code :

[build]
compiler = mingw32
  • Remove all instances of "-mno-cygwin" gcc option from file "C:\Python27\Lib\distutils\cygwinccompiler.py" :

This :

    self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
                         compiler_so='gcc -mno-cygwin -mdll -O -Wall',
                         compiler_cxx='g++ -mno-cygwin -O -Wall',
                         linker_exe='gcc -mno-cygwin',
                         linker_so='%s -mno-cygwin %s %s'
                                    % (self.linker_dll, shared_option,
                                       entry_point))

Becomes this :

self.set_executables(compiler='gcc -O -Wall',
                     compiler_so='gcc -mdll -O -Wall',
                     compiler_cxx='g++ -O -Wall',
                     linker_exe='gcc',
                     linker_so='%s %s %s'
                                % (self.linker_dll, shared_option,
                                   entry_point))

The second point can be necessary in case you are using a recent version of gcc, where the deprecated option -mno-cygwin has been removed.

Hope this will help even if it is not directly related to the OP real needs (but still related to the question's title...)

I just took a look at the distutils source, and the --compiler option expects "unix", "msvc", "cygwin", "mingw32", "bcpp", or "emx". It checks the compiler name you want by checking the CC environment variable. Try calling build like this:

CC=gcc python setup.py build

You don't need to set CXX, it doesn't check for that.

Try this: http://mail.python.org/pipermail/distutils-sig/2002-August/002944.html

In short, it appears that you should try: python setup.py build --compiler=g++ first.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!