[Patches] [ python-Patches-1324762 ] Compiling and linking main() with C++ compiler

SourceForge.net noreply at sourceforge.net
Thu Nov 10 19:42:23 CET 2005

Patches item #1324762, was opened at 2005-10-12 13:45
Message generated for change (Comment added) made by cludwig
You can respond by visiting: 

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Build
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Christoph Ludwig (cludwig)
Assigned to: Nobody/Anonymous (nobody)
Summary: Compiling and linking main() with C++ compiler

Initial Comment:
The attached patch proposes a resolution to the discussion 
started in 
regarding the compiler (C vs. C++) used to compile python's 
main() and to link the executable.  
The patch contains the following changes: 
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 
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++ extensions.)  
5) Modules/ccpython.cc is no longer used and can be 


>Comment By: Christoph Ludwig (cludwig)
Date: 2005-11-10 19:42

Logged In: YES 

I am going to upload a revision of my patch that addresses 
jackjansen's comment: It sets CXX to g++ or c++ if CC is gcc or 
cc, respectively. Additionally, it writes a warning if configure had to 
"guess" the C++ compiler and tells the user how to override this 
The change is in lin with jackjansen's second suggestion. It is 
pretty straight forward and avoids fragile configure magic. 


Comment By: Jack Jansen (jackjansen)
Date: 2005-11-08 23:51

Logged In: YES 

One question: is step 4 a wise idea? Picking a random C++ compiler if 
multiple are available may result in picking a vendor C++ when the user 
has specified CC=gcc, for example.

OTOH, actually doing the configure magic to determine that the selected 
C++ works together with the c-compiler selected for Python may be 
overkill too.

Maybe try only standard combinations cc/c++ gcc/g++ and otherwise 
require --with{out}-cxx?


You can respond by visiting: 

More information about the Patches mailing list