extending python with a C-written dll

John Machin sjmachin at lexicon.net
Mon Dec 20 16:03:08 EST 2004


Jean-Baptiste PERIN wrote:
> Hi,
>
> I'm trying to make a windows dll reachable from a python script ..
and
> I'm encountering troubles during link step ..
>
> I use "lcc" to compile and link
> I use python 2.3 under win XP
[snip]
> Here are the errors :
> ---------------------
> Error c:\...\plugins\hello.c 14 undefined reference to
__imp__Py_BuildValue
> Error c:\...\plugins\hello.c 46 undefined reference to
__imp__Py_InitModule4
[snip]
>      return Py_BuildValue("i", 1);
[snip]
> void __declspec(dllexport) inithello()
> {
>      (void)Py_InitModule3("hello", helloMethods, MHello__doc__);
> Can anyone help me?

Yes. Option 1: *Maybe* you can help yourself. Have you not noticed from
the above that the compiler is magically prepending "__imp__" to the
names of external functions? However the .lib that comes with Python
won't have that "__imp__". You would have to bridge that gap, somehow.
Have you searched the lcc documentation? Are you prepared for the next
several problems that may arise?

By the way, lcc also *appears* to change "...Module3" to "...Module4"
:-)

Option 2: You have been helped already. There are two free compilers
which work quite well for developing extensions in C for win32
platforms; start reading here:

http://docs.python.org/inst/tweak-flags.html#SECTION000620000000000000000




More information about the Python-list mailing list