C Extensions: calling across extensions
Gustavo Cordova
gcordova at hebmex.com
Wed May 29 18:25:04 EDT 2002
>
> I have two C Extension modules written for python. Within
> one module I want to create an instance of an object within
> another module. Say the modules are named A and B. Within
> A I have a creation method that looks something like:
>
> PyObject* A_new (int param)
> {
> AType* self = PyObject_New (AType, &AType_definition);
> self->param = param;
> return (PyObject*)self;
> }
>
> within B i try to create an instance of AType like:
>
> PyObject* A_new (int param);
> PyObject* somefunction (PyObject* self, PyObject* args)
> {
> PyObject* p = A_new (5);
> return p;
> }
>
> both of these functions are in seperate modules in seperate .so files
> (linux). I can import module A and everything works perfectly. when i
> import module B i get the error:
> Import Error: ./B.so: undefined symbol: A_new
>
> i compile both with
> gcc -shared -o A.so A.c
> gcc -shared -o B.so B.c
>
> do i need to do special declarations for importing and exporting
> functions across shared objects for python extension modules?
> do i need
> to compile with a -l option? any help would be appreciated.
>
> thanks, Maxwell Sayles
>
You need to link B.c against A.so, so that it'll know
from where to import any needed symbols:
gcc -shared -o B.so B.c A.so
(I think)
Also, use the -fPIC flag, to create relocatable code.
Good luck :-)
-gus
More information about the Python-list
mailing list