[Python-Dev] [C++-sig] GCC version compatibility

Christoph Ludwig cludwig at cdc.informatik.tu-darmstadt.de
Wed Oct 12 14:09:18 CEST 2005


this is to continue a discussion started back in July by a posting by 
Dave Abrahams <url:http://thread.gmane.org/gmane.comp.python.devel/69651>
regarding the compiler (C vs. C++) used to compile python's main() and to link
the executable.

On Sat, Jul 16, 2005 at 12:13:58PM +0200, Christoph Ludwig wrote:
> On Sun, Jul 10, 2005 at 07:41:06PM +0200, "Martin v. Löwis" wrote:
> > Maybe. For Python 2.4, feel free to contribute a more complex test. For
> > Python 2.5, I would prefer if the entire code around ccpython.cc was
> > removed.
> I submitted patch #1239112 that implements the test involving two TUs for
> Python 2.4. I plan to work on a more comprehensive patch for Python 2.5 but
> that will take some time.

I finally had the spare time to look into this problem again and submitted
patch #1324762. The proposed patch implements the following:

1) The configure option --with-cxx is renamed --with-cxx-main. This was done
to avoid surprising the user by the changed meaning. Furthermore, it is now
possible that CXX has a different value than provided by --with-cxx-main, so
the old name would have been confusing. 
2) The compiler used to translate python's main() function is stored in the
configure / Makefile variable MAINCC. By default, MAINCC=$(CC). If
--with-cxx-main is given (without an appended compiler name), then
MAINCC=$(CXX). If --with-cxx-main=<compiler> is on the configure command line,
then MAINCC=<compiler>. Additionally, configure sets CXX=<compiler> unless CXX
was already set on the configure command line. 
3) The command used to link the python executable is (as before) stored in
LINKCC. By default, LINKCC='$(PURIFY) $(MAINCC)', i.e. the linker front-end is
the compiler used to translate main(). If necessary, LINKCC can be set on the
configure command line in which case it won't be altered. 
4) If CXX is not set by the user (on the command line or via --with-cxx-main),
then configure tries several likely C++ compiler names. CXX is assigned the
first name that refers to a callable program in the system. (CXX is set even
if python is built with a C compiler only, so distutils can build C++
5) Modules/ccpython.cc is no longer used and can be removed. 

I think that makes it possible to build python appropriately on every

- By default, python is built with the C compiler only; CXX is assigned the
  name of a "likely" C++ compiler. This works fine, e.g., on ELF systems like
  x86 / Linux where  python should not have any dependency on the C++
  runtime to avoid conflicts with C++ extensions. distutils can still build
  C++ extensions since CXX names a callable C++ compiler.

- On platforms that require main() to be a C++ function if C++ extensions are
  to be imported, the user can configure python --with-cxx-main. On platforms
  where one must compile main() with a C++ compiler, but does not need to link
  the executable with the same compiler, the user can specify both
  --with-cxx-main and LINKCC on the configure command line.

Best regards


LiDIA: http://www.informatik.tu-darmstadt.de/TI/LiDIA/Welcome.html

More information about the Python-Dev mailing list