Extending Python with C++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jeremito

    #1

    Extending Python with C++

    I am learning how to extend Pythong with C++. I have will be writing
    some code in C++ and want/need Python to interact with it. I am not
    having success following the online documentation from
    http://docs.python.org/ext/ext.html. I have also looked briefly at
    some of the demos in the source code distribution. Can anyone help me?
    I am using the MacPython (version 2.4) distribution.

    I have one specific question. The documentation online states:

    "If the main program (the Python interpreter) is compiled and linked by
    the C compiler, global or static objects with constructors cannot be
    used. This is not a problem if the main program is linked by the C++
    compiler."

    Thanks,
    Jeremy

  • Fredrik Lundh

    #2
    Re: Extending Python with C++

    "jeremito" <jeremit0@gmail .com> wrote:
    [color=blue]
    > I have one specific question. The documentation online states:
    >
    > "If the main program (the Python interpreter) is compiled and linked by
    > the C compiler, global or static objects with constructors cannot be
    > used. This is not a problem if the main program is linked by the C++
    > compiler."[/color]

    what is the question ?

    </F>



    Comment

    • jeremito

      #3
      Re: Extending Python with C++

      Oops, sorry. My question is, how can I know if my Python interpreter
      was lined by C++? The non-specific questions are, of course, does
      anyone have any hints or suggestions? Good websites to visit?
      Thanks,
      Jeremy

      Comment

      • Brian van den Broek

        #4
        Re: Extending Python with C++

        jeremito said unto the world upon 29/12/05 11:39 AM:[color=blue]
        > I am learning how to extend Pythong with C++. I have will be writing
        > some code in C++ and want/need Python to interact with it. I am not
        > having success following the online documentation from
        > http://docs.python.org/ext/ext.html. I have also looked briefly at
        > some of the demos in the source code distribution. Can anyone help me?
        > I am using the MacPython (version 2.4) distribution.
        >
        > I have one specific question. The documentation online states:
        >
        > "If the main program (the Python interpreter) is compiled and linked by
        > the C compiler, global or static objects with constructors cannot be
        > used. This is not a problem if the main program is linked by the C++
        > compiler."
        >
        > Thanks,
        > Jeremy[/color]

        I have a specific answer.

        Best,

        Brian vdB

        Comment

        • Martin v. Löwis

          #5
          Re: Extending Python with C++

          jeremito wrote:[color=blue]
          > Oops, sorry. My question is, how can I know if my Python interpreter
          > was lined by C++?[/color]

          Ah. This documentation fragment is somewhat wrong: it depends on the
          target operating system and compiler whether you have to link main
          with a C++ compiler. For many modern systems, this isn't necessary.

          Anyway, finding out whether the executable was linked with a C++
          compiler is only possible with platform-dependent tools. For example,
          on Linux and many Unix systems, ldd(1) will tell you whether a C++
          library was linked into the binary; do 'ldd python'.
          [color=blue]
          > The non-specific questions are, of course, does
          > anyone have any hints or suggestions?[/color]

          You should really understand the concept of 'extern "C"' in C++.
          That's all you need to know write Python extensions in C++.

          Regards,
          Martin

          Comment

          • Brian van den Broek

            #6
            Re: Extending Python with C++

            Brian van den Broek said unto the world upon 29/12/05 12:03 PM:[color=blue]
            > jeremito said unto the world upon 29/12/05 11:39 AM:
            >[color=green]
            >>I am learning how to extend Pythong with C++. I have will be writing
            >>some code in C++ and want/need Python to interact with it. I am not
            >>having success following the online documentation from
            >>http://docs.python.org/ext/ext.html. I have also looked briefly at
            >>some of the demos in the source code distribution. Can anyone help me?
            >> I am using the MacPython (version 2.4) distribution.
            >>
            >>I have one specific question. The documentation online states:
            >>
            >>"If the main program (the Python interpreter) is compiled and linked by
            >>the C compiler, global or static objects with constructors cannot be
            >>used. This is not a problem if the main program is linked by the C++
            >>compiler."
            >>
            >>Thanks,
            >>Jeremy[/color]
            >
            >
            > I have a specific answer.
            >
            > Best,
            >
            > Brian vdB[/color]


            Hello all,

            while I think the point I was making was correct, I know I expressed
            it in a snide and unkind way. Apologies to all, especially to the OP.

            Sheepishly,

            Brian vdB

            Comment

            • jeremito

              #7
              Re: Extending Python with C++

              Unfortunately, I need to know a bit more than just the concept 'extern
              "C"'. I am really slow at this. Can anyone point me towards some
              examples or a tutorial (other than the one from python.org, I didn't
              understand that one)?
              Thanks,
              Jeremy

              Comment

              Working...