distutils and ctypes

jtravs at gmail.com jtravs at gmail.com
Tue Jan 9 13:46:15 EST 2007


Hi all,

I suspect that I'm doing something stupid, I would like some other
opinions though.
I'm getting started with ctypes and am trying to use distutils to help
build my module. At the moment I simply want distutils to build a
shared c library (not a python extension!). Under linux, the following
works, under windows xp id doesn't (which I guess is obvious, but the
linux success lead me on).
I have two files at the moment...

/* begin test.c */
int test(int i)
{
    return i*i;
}
/* end test.c */

#begin setup.py
from distutils.core import setup, Extension
setup(name="test", version="0.0", ext_modules = [Extension("test",
["test.c"])])
# end setup.py

If I run:

python setup.py build

under linux, I get a nice shared c library under my build dir, which
can be imported by ctypes.
If I run it under windows I get the following:

running build
running build_ext
building 'test' extension
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\link.exe
/DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python25\libs
/LIBPATH:C:\Python25\PCBuild /EXPORT:inittest
build\temp.win32-2.5\Release\test.obj /OUT:build\lib.win32-2.5\test.pyd
/IMPLIB:build\temp.win32-2.5\Release\test.lib
LINK : error LNK2001: unresolved external symbol inittest
build\temp.win32-2.5\Release\test.lib : fatal error LNK1120: 1
unresolved externals
LINK : fatal error LNK1141: failure during build of exports file

I can see the problem: python is trying to build an extension module
and is telling the linker to export "inittest", which doesn't exist.
This didn't happen under linux as you don't need to export interfaces
in shared c libraries on linux.

So finally, my question is, is there a way to get distutils to simply
build a shared library on windows so that I can use ctypes with them???

Thanks for your patience with this post, and thanks for any replies.
Best regards,
John Travers




More information about the Python-list mailing list