views:

37

answers:

1

I'm abusing distutils to compile an extension module for Python, but rather than using the Python C API I'm using ctypes to talk to the resulting shared library.

This works fine in Linux because it automatically exports all symbols in a shared library, but in Windows distutils provides a .def to export only the Python module init function.

How do I extend distutils to provide my own .def on Windows so it will export the symbols I need?

+1  A: 

You can pass ['-Wl,--export-all-symbols'] as extra_link_args if you're using Mingw's GCC. There's probably a similar setting for Visual, somewhere in the IDE.

This works only if distutils chooses to use "gcc -mdll" as a linker instead of "dllwrap". It does so if your ld version is later than 2.10.90, which should be the case if you're using a recent Mingw. At first it didn't work for me because I used Python 2.2 which has a small bug related to version parsing: it expects 3 dot-separated numbers so it falls back to dllwrap if the ld version is 2.20...

fraca7
I'm aware of that option, but will it work in the presence of a distutils-provided .def file?
joeforker
Nah, the __declspec does not work either. That's very strange, here at work we do have .pyd built through distutils that export all of their symbols. I'll dig a bit...
fraca7