[Pythonmac-SIG] Extending python in C++
Chris Barker
Chris.Barker@noaa.gov
Tue, 10 Dec 2002 08:19:16 -0800
> > I'm trying to extend python with some C++ source, [...]
> >
> > void initdemo()
> > {
> > Py_InitModule("demo", demoMethods);
> > }
>
> You need an extern "C" construct for that one, otherwise the symbol
> name will be name-mangled according to the C++ rules.
To be precise, you need:
extern "C" void initdemo()
{
Py_InitModule("demo", demoMethods);
}
I don't what version of Python or what compiler you're using, but I also
had a problem linking a C++ extension to the Python that came with
Jaguar. this was Jack's response to my problem:
> This just came by on another mailing list. The problem is that
> the link step is done with "gcc", not "g++", so you have to add
> the C++ library by hand. The easiest is to add an
> extra_link_libraries (iirc) flag to the setup.py file.
Honestly, I havn't tried it. I was only using C++ for a few handy syntax
improvements over C, so I just re-wrote my extension in C (I had done
this before Jack posted that tip)
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov