You are not logged in.

#1 2012-08-31 18:58:40

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 861

Python extension: multiple init in a single shared library

Hi, I'm playing with python extension using C/C++ and I have a question. When writing some extension library, say libFoo.so, you have to put a PyMODINIT_FUNC initFoo(void) function inside it, which will be executed when loading the library from the python shell (import Foo) or from a C program using the Python/C API. I would like to know if it is possible to specify the name of the init function to be executed when importing the library. I would like to use a different name for the init function, but my final goal would be to place many init inside the same library and choose which of them are to be executed at import time.
According to the Python reference guide and my Google searches, I would say that this is not possible, but maybe some skilled developer in this forum knows better than me...
Thanks.

Last edited by snack (2012-08-31 18:58:52)

Offline

#2 2012-08-31 19:11:11

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: Python extension: multiple init in a single shared library

snack wrote:

Hi, I'm playing with python extension using C/C++ and I have a question. When writing some extension library, say libFoo.so, you have to put a PyMODINIT_FUNC initFoo(void) function inside it, which will be executed when loading the library from the python shell (import Foo) or from a C program using the Python/C API. I would like to know if it is possible to specify the name of the init function to be executed when importing the library. I would like to use a different name for the init function, but my final goal would be to place many init inside the same library and choose which of them are to be executed at import time.
According to the Python reference guide and my Google searches, I would say that this is not possible, but maybe some skilled developer in this forum knows better than me...
Thanks.

You could try to create your library as libFoo with initFoo and initBar and create a symlink named libBar in order to call the second function.

Last edited by progandy (2012-08-31 19:11:42)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#3 2012-08-31 19:14:46

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 861

Re: Python extension: multiple init in a single shared library

progandy wrote:

You could try to create your library as libFoo with initFoo and initBar and create a symlink named libBar in order to call the second function.

Nice idea, I didn't thought about it. But I would need something that does not require hacks like creating a symlink: ideally I need to be able to select the init function just using the C API. But thanks for your suggestion smile

Offline

Board footer

Powered by FluxBB