Extending Python with C++

J

jeremito

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
 
F

Fredrik Lundh

jeremito said:
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."

what is the question ?

</F>
 
J

jeremito

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
 
B

Brian van den Broek

jeremito said unto the world upon 29/12/05 11:39 AM:
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

I have a specific answer.

Best,

Brian vdB
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

jeremito said:
Oops, sorry. My question is, how can I know if my Python interpreter
was lined by C++?

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'.
The non-specific questions are, of course, does
anyone have any hints or suggestions?

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
 
B

Brian van den Broek

Brian van den Broek said unto the world upon 29/12/05 12:03 PM:
jeremito said unto the world upon 29/12/05 11:39 AM:



I have a specific answer.

Best,

Brian vdB


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
 
J

jeremito

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
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,130
Latest member
MitchellTe
Top