[Pythonmac-SIG] Extending python in C++

Matthew Smith mps@viewbuild.com
Wed, 11 Dec 2002 13:11:54 +1100


>>> 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);
> }

Thanks.

> 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)

What exactly do you mean? I've managed to get the cpp extension file to
compile and work with python, but I am now having issues getting distutils
to recognise a library I am using...

It's called libcryptopp.a and I have it in the distribution directory, with
it's header files in crypto42 directory.

Try as I might, I can't get distutils to find the library.

Any Ideas?

I suppose my best bet is to subscribe to the distutils SIG.

Cheers

Matt