By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,551 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,551 IT Pros & Developers. It's quick & easy.

Can Python be compiled by a C++ compiler ?

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Helmut Jarausch wrote:
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

Jul 18 '05 #2

P: n/a
At some point, Helmut Jarausch <ja******@skynet.be> wrote:
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++.

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.