Python extension modules are just dynamic libraries, so I assume that you can dynamically link a Python extension to another. The problem with Windows Python Extensions is the extension .pydinstead .dll, so I can't get distutils to refer to them when I run the installation script. (I don't think this is a problem on UNIX, since Python extensions use the extension .so.)
Suppose I have an extension bar.pydthat I need to associate with foo.pyd. Basically, what I did in setting up the script was:
from distutils.core import setup, Extension
foo = Extension("foo", sources=["foo.c"])
bar = Extension("bar", libraries=["foo"], sources=["bar.c"])
setup(ext_modules=[foo, bar])
This is not working yet. Is it possible? I suppose this is so, but I could not find anything on the Internet. I use MinGW on Windows, but I would like it to work with other MSVC ++ and other systems.
Edit: I previously solved this problem by passing the object file ( foo.o) created when it foowas compiled into a parameter extra_objectsin the extension (this will only work if I defined the prototypes of all the foocharacters in bar):
bar = Extension("bar", sources=["bar.c"], extra_objects=["build/.../foo.o"]
This did not seem to be the right solution, but it worked. I don't understand dynamic linking very well, so this may be the right way to do this. However, this is very bad.
Then I tried passing some explicit gcc arguments to compile the import library:
foo = Extension("foo", sources=["foo.c"], extra_compile_args=["-Wl,--out-implib,foo.lib,--export-all-symbols"])
And then I linked barto the new import library:
bar = Extension("bar", libraries=["foo"], sources=["bar.c"])
, ( , PyTypeObject foo, , , bar. PyTypeObject .).
2: , . , , PyTypeObject . , foo PyTypeOject Foo_Type. foo.h, foo.c, bar.c:
PyTypeObject Foo_Type;
foo.c:
PyTypeObject __declspec(dllexport) Foo_Type;
bar.c:
PyTypeObject __declspec(dllimport) Foo_Type;
. Foo_Type foo, bar, Foo_Type. , , Windows. , __declspec, .