[Distutils] How to specify the compiler
Michiel Jan Laurens de Hoon
mdehoon@ims.u-tokyo.ac.jp
Sun Aug 18 22:06:32 2002
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