Can Python be compiled by a C++ compiler ?

Discussion in 'Python' started by Helmut Jarausch, May 12, 2004.

  1. 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
    Helmut Jarausch, May 12, 2004
    #1
    1. Advertising

  2. 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
    Daniel Dittmar, May 12, 2004
    #2
    1. Advertising

  3. At some point, Helmut Jarausch <> 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
    David M. Cooke, May 12, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jack Wright
    Replies:
    5
    Views:
    611
    Shiv Kumar
    Jan 19, 2004
  2. Klaus Schneider
    Replies:
    1
    Views:
    527
    Rolf Magnus
    Dec 2, 2004
  3. lander
    Replies:
    5
    Views:
    577
    bruce barker
    Mar 5, 2008
  4. Tony
    Replies:
    0
    Views:
    455
  5. Immortal Nephi
    Replies:
    12
    Views:
    874
    Paul Bibbings
    Jul 30, 2010
Loading...

Share This Page