Python extensions using MinGW and CXX

Reinhard Nadrchal reinhard at proceryon.at
Fri Feb 14 04:51:36 EST 2003



Gerhard Häring wrote:

>* Reinhard Nadrchal <reinhard at proceryon.at> [2003-02-14 08:09 +0100]:
>  
>
>>So do you think the problem cannot be solved without distutils ?
>>    
>>
>
>Of course not. If nothing else, you can look at the distutils output for
>compiler settings that work.
>
>Also, be sure to follow the steps in the Python documentation for creating an
>import library.
>
>FWIW, this seems to work here:
>
>g++ foo.cpp -Ic:/python22/include -Lc:/python22/libs -lpython22 -mdll -ofoo.pyd
>
>If it still doesn't work, I'd recommend you post again in the same thread at
>python-list telling us which *exact* error message from the compiler/linker
>you're getting.
>
>Good luck.
>
>& Servus ;-)
>
>Gerhard
>
To create the python import library I did the following (with my 
specific paths provided):

pexports /C/WINDOWS/system32/python20.dll > python20.def
dlltool  --dllname /C/WINDOWS/system32/python20.dll --def python20.def 
--output-lib libpython20.a
and copied libpython20.a to the Python20/libs directory.

If I link the library with something like:
g++ -Ld:/Python20/libs -lpython20 -mdll foo.o -ofoo.pyd
I get a lot of undefined references:
<snip>
example_py2cc.o: In function 
`ZNSt8_Rb_treeISsSt4pairIKSsPN2Py12MethodDefExtI8C_ModuleEEESt10_Select1stIS7_ESt4lessISsESaIS7_EE9_S_parentEPSt13_Rb_tree_nodeIS7_E':
d:/programme/GNU/MinGW/include/c++/3.2/bits/stl_tree.h(.text$_ZNK2Py5Float7acceptsEP7_object+0x19): 
undefined reference to `PyFloat_Type'
IndirectPythonInterface.o: In function `ZN2Py20_Exc_ArithmeticErrorEv':
d:/Projects/Cassandra/Internal/Source/ExampleCXX/IndirectPythonInterface.cxx:449: 
undefined reference to `PyExc_ArithmeticError'
IndirectPythonInterface.o: In function `ZN2Py19_Exc_AssertionErrorEv':
d:/Projects/Cassandra/Internal/Source/ExampleCXX/IndirectPythonInterface.cxx:450: 
undefined reference to `PyExc_AssertionError'
I
.
.
.
<snap>

If I, on the other hand, link in python20.dll I get no errors and ld 
seems to be happy. The trouble starts when I execute 'import foo' from 
the python interpreter -  it simply crashes without  any comment.

g++ -shared -lpython20 foo.o -ofoo.pyd

That's the way I've tried it so far. I've also tried to link without the 
-shared option using -mdll, but in this case Python doesn't recognize 
the 'initfoo' entry point - maybe this is the key ?! Ho do I have to 
declare/define the init function ???

Danke :-)
reinhard




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20030214/078c0a7e/attachment.html>


More information about the Python-list mailing list