Can Python be compiled by a C++ compiler ?

H

Helmut Jarausch

Hi,

having read http://www.python.org/doc/current/ext/ext.html by Guido van
Rossum and Fred Drake,
I got the impression I should compile Python with g++ since section 1.11
indicates that otherwise the constructor of a global or static object
(of an extension in C++) won't be called.

Now trying to build Python (CVS version) with g++ fails. E.g., one
problem is in Parser/pgen.c line 364 with a typical C-like confusion of
types and variables when it declares

ss_arc *ss_arc
where ss_arc is defined by a previous typedef. A C++ compiler won't
accept this.

Do I miss something?

Many thanks for your comments,

Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
 
D

Daniel Dittmar

Helmut said:
having read http://www.python.org/doc/current/ext/ext.html by Guido
van Rossum and Fred Drake,
I got the impression I should compile Python with g++ since section
1.11 indicates that otherwise the constructor of a global or static
object (of an extension in C++) won't be called.

Now trying to build Python (CVS version) with g++ fails. E.g., one

You'll need to link Python using C++. This is necessary to include the C++
runtime. The individual .c files should be compiled with C.

I believe that using C++ for the link step is even the default choosen by
../configure. Otherwise, extensions such as wxPython wouldn't work out of the
box as they contain code written in C++.

Daniel
 
D

David M. Cooke

At some point said:
Hi,

having read http://www.python.org/doc/current/ext/ext.html by Guido
van Rossum and Fred Drake,
I got the impression I should compile Python with g++ since section 1.11
indicates that otherwise the constructor of a global or static object
(of an extension in C++) won't be called.

Now trying to build Python (CVS version) with g++ fails. E.g., one
problem is in Parser/pgen.c line 364 with a typical C-like confusion
of types and variables when it declares

ss_arc *ss_arc
where ss_arc is defined by a previous typedef. A C++ compiler won't
accept this.

Do I miss something?

Yes. Just specify the C++ compiler to the configure script with the
--with-cxx option. My guess it already does this automatically, and
you're just making more work for yourself.

Everything will be compiled with the C compiler (gcc), but will be
linked by the C++ compiler. This assures that the appropiate run-time
stuff needed for C++ extensions is linked in (or something like that),
without actually having to rewrite Python in C++.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top