
I am trying to use distutils to install a Python extension module. The extension module needs gcc to compile. Unfortunately, on my unix system, distutils uses the standard C compiler cc instead of gcc, and the compilation fails. The gcc compiler is available on our system; however, I don't know how to tell distutils to use gcc instead of cc. Some people on comp.lang.python have told me that distutils looks for the environment variable CC, and uses the corresponding compiler for the build process. However, I couldn't get this to work on my Unix system. Both set CC=gcc and setenv CC gcc didn't have any effect. Likewise, export CC=gcc is ignored on my Cygwin system. In an effort to get to the bottom of this, I looked at the distutils source code. As far as I can tell, distutils calls customize_compiler, which calls get_config_vars, which calls _init_posix, which calls parse_makefile. This then finds the arguments supplied to get_config_vars from the python Makefile. Does anybody know where the checks for the environment variables are made? If no such checks are made, is this something that should be added to distutils? I am willing to spend some time on this to get this working. Below I copied some output of my trials with distutils. Thanks in advance, --Michiel. University of Tokyo, Human Genome Center blue{mdehoon}23: set CC=gcc blue{mdehoon}24: python setup.py build running build running build_py not copying Pycluster/__init__.py (output up-to-date) running build_ext building 'Pycluster.cluster' extension cc -DNDEBUG -O -OPT:Olimit=0 -Iranlib/src -I/usr/local/include/python2.2 -c cluster.c -o build/temp.irix64-6.5-2.2/cluster.o ... and so on With setenv CC gcc, I get the same result: blue{mdehoon}6: setenv CC gcc blue{mdehoon}7: python setup.py build running build running build_py not copying Pycluster/__init__.py (output up-to-date) running build_ext building 'Pycluster.cluster' extension cc -DNDEBUG -O -OPT:Olimit=0 -Iranlib/src -I/usr/local/include/python2.2 -c clus ter.c -o build/temp.irix64-6.5-2.2/cluster.o ... and so on. I have tried export CC=bcc32 before on Cygwin, just to see what would happen, but that also got ignored by distutils: mdehoon@GINSENG ~/Cluster-1.01 $ export CC=bcc32 mdehoon@GINSENG ~/Cluster-1.01 $ bcc32 -v Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland Error E2266: No file names given mdehoon@GINSENG ~/Cluster-1.01 $ python setup.py build running build running build_py creating build creating build/lib.cygwin-1.3.12-i686-2.2 creating build/lib.cygwin-1.3.12-i686-2.2/Pycluster copying Pycluster/__init__.py -> build/lib.cygwin-1.3.12-i686-2.2/Pycluster running build_ext building 'Pycluster.cluster' extension creating build/temp.cygwin-1.3.12-i686-2.2 gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -DUSE_DL_IMPORT -Iranlib/src -I/usr/include/python2.2 -c cluster.c -o build/temp.cygwin-1.3.12-i686-2.2/cluster.o ... and so on

Hi, I have used the following hack to replace gcc with g++ in my setup.py files. You can easily change it to you needs, I believe. Pearu #+++HACK: replace linker gcc with g++ +++++++++++ disable_opt = 0 gcc_exe = 'gcc' gpp_exe = 'g++' from distutils import sysconfig save_init_posix = sysconfig._init_posix def my_init_posix(): save_init_posix() g = sysconfig._config_vars for n,r in [('LDSHARED',gpp_exe),('CC',gcc_exe)]: if g[n][:3]=='gcc': print 'my_init_posix: changing %s = %r'%(n,g[n]), g[n] = r+g[n][3:] print 'to',`g[n]` if disable_opt and g['OPT'][:15]=='-DNDEBUG -g -O3': print 'my_init_posix: changing OPT =',`g['OPT']`, g['OPT'] = ' -DNDEBUG -g '+g['OPT'][15:] print 'to',`g['OPT']` sysconfig._init_posix = my_init_posix #++++++++++++++++++++++++

see below for comments. Michiel Jan Laurens de Hoon wrote:
I am trying to use distutils to install a Python extension module. The extension module needs gcc to compile. Unfortunately, on my unix system, distutils uses the standard C compiler cc instead of gcc, and the compilation fails. The gcc compiler is available on our system; however, I don't know how to tell distutils to use gcc instead of cc.
Some people on comp.lang.python have told me that distutils looks for the environment variable CC, and uses the corresponding compiler for the build process. However, I couldn't get this to work on my Unix system. Both set CC=gcc and setenv CC gcc didn't have any effect. Likewise, export CC=gcc is ignored on my Cygwin system.
In an effort to get to the bottom of this, I looked at the distutils source code. As far as I can tell, distutils calls customize_compiler, which calls get_config_vars, which calls _init_posix, which calls parse_makefile. This then finds the arguments supplied to get_config_vars from the python Makefile. Does anybody know where the checks for the environment variables are made? If no such checks are made, is this something that should be added to distutils? I am willing to spend some time on this to get this working.
Below I copied some output of my trials with distutils.
Thanks in advance,
--Michiel. University of Tokyo, Human Genome Center
blue{mdehoon}23: set CC=gcc blue{mdehoon}24: python setup.py build running build running build_py not copying Pycluster/__init__.py (output up-to-date) running build_ext building 'Pycluster.cluster' extension cc -DNDEBUG -O -OPT:Olimit=0 -Iranlib/src -I/usr/local/include/python2.2 -c cluster.c -o build/temp.irix64-6.5-2.2/cluster.o
... and so on
With setenv CC gcc, I get the same result:
blue{mdehoon}6: setenv CC gcc blue{mdehoon}7: python setup.py build running build running build_py not copying Pycluster/__init__.py (output up-to-date) running build_ext building 'Pycluster.cluster' extension cc -DNDEBUG -O -OPT:Olimit=0 -Iranlib/src -I/usr/local/include/python2.2 -c clus ter.c -o build/temp.irix64-6.5-2.2/cluster.o ... and so on.
Distuitls use always the compiler used for compilation of Python. It reads it from the Python Makefile, if I remember right. And it get there also the compiler options. So a possible solution would be create an script called cc, put in your PATH and try it this way. This script has then to call your prefered compiler and possibly also modify the compiler options if necessary.
I have tried export CC=bcc32 before on Cygwin, just to see what would happen, but that also got ignored by distutils:
On Windows to use Borland's Compiler try python setup.py build --compiler=bcpp

On Monday, August 19, 2002, at 10:08 , Rene Liebscher wrote:
Distuitls use always the compiler used for compilation of Python. It reads it from the Python Makefile, if I remember right. And it get there also the compiler options. So a possible solution would be create an script called cc, put in your PATH and try it this way.
Note that you aree living dangerously if you're pulling trics like this. Mixing object files generated by gcc with object files generated with cc isn't guaranteed to work, that's one of the reasons distutils picks the same compiler as was used to build Python itself. If you must absolutely use gcc the best solution is probably to rebuild Python with gcc. -- - Jack Jansen <Jack.Jansen@oratrix.com> http://www.cwi.nl/~jack - - If I can't dance I don't want to be part of your revolution -- Emma Goldman -

Jack Jansen <Jack.Jansen@cwi.nl> writes:
Note that you aree living dangerously if you're pulling trics like this. Mixing object files generated by gcc with object files generated with cc isn't guaranteed to work, that's one of the reasons distutils
For plain C (not C++) that should work, as gcc uses the calling conventions of the native C compiler. And under Linux, where gcc is "native", other compilers proudly announce gcc linking compatibility. While there remains a small risk of incompatibility, I would like to see some straightforward way to change compilers as well. For example, I would like to try Intel's new C compiler for Linux on some modules, but I haven't done so yet because it's too much work either to recompile Python (and all add-on packages) or to work around distutils. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais -------------------------------------------------------------------------------
participants (5)
-
Jack Jansen
-
Konrad Hinsen
-
Michiel Jan Laurens de Hoon
-
Pearu Peterson
-
Rene Liebscher