C++ calling a Python extension module

Gordon McMillan gmcm at hypernet.com
Tue Dec 7 09:50:59 EST 1999


Jeremy Black wrote:

> Is there a limitation or bug in the NT version of Python that
> disallows importing python extension modules from C++?

No.
 
> I am having difficulty importing a python module from C++ that
> imports a python extension module written in C.  

I'd guess that there's a problem in the way you've built your 
app. For example, you won't be able to load C extensions if 
you've statically linked Python to your app - you have to leave 
Python in a dll.  You have to be very careful to get consistent 
settings for libraries and _DEBUG etc across all pieces. This 
can be a real pain, because _DEBUG will automatically cause 
a link to python15_d.lib (python15_d.dll) and then all C 
extensions will also need to be *_d.dll/pyd (and you'll need to 
build your own python15_d.dll and *_d.dll/pyd).

With a bit of trickery, you can get your stuff built with debug, 
but still link to non-debug Python (so you need to use the non-
debug c runtime dll). This is usually good enough.

[snipped code, which is not where the problem is...]

- Gordon




More information about the Python-list mailing list