Python loading library containing embedded python...

"Martin v. Löwis" martin at v.loewis.de
Sun Jan 29 03:42:12 EST 2006


Brennus wrote:
> I have a dll/so which embeds python. I can verify it works by
> compiling it as an executable and adding an appropriate main.

Please explain in more detail how you did the embedding. Did you
statically link the Python interpreter into your dll/so, or did
you use a shared one?

> How can I make my dll/so with embedded python support use via ctypes?

Whether you can do this at all depends on the fine details of
embedding: e.g. what operating system, how precisely did you do
the embedding, and so on.

For example, on many Unix systems, you might end up with two definitions
of all the Python symbols, at which point it depends on the precise
linker command line options to determine what precisely happens
(e.g. which of the definition of the symbol is used in what place).

> The dll/so must support use in processes which might contain other
> instances of Python. I can not change that requirement. Running via
> ctypes is an easy test of this capability (or much of it I suspect).

Then your best bet is to *really* embed Python. I.e. link all symbols
statically, preferably renaming them (if possible), and make sure that
the resulting dll does neither reference nor expose any Python symbols.
Given the different linkers on different systems, this is very tricky
to implement.

Regards,
Martin



More information about the Python-list mailing list