Mailing List Archive

load_dynamic problem
Hey folks,

I'm having a bit of trouble loading a C extension into Python 1.5.2.
I'm getting the error:

Traceback (innermost last):
File "<stdin>", line 1, in ?
File "bpinter.py", line 9, in ?
PyBPMPD = imp.load_dynamic('PyBPMPD', 'PyBPMPD.so')
ImportError: ./PyBPMPD.so: undefined symbol: setdef

setdef, not written by me, but called from inside PyBPMPD.c, is
prototyped as:
extern int setdef(bpmparam *);

The module itself compiles without complaint with:
gcc -I/usr/include/python1.5/ -shared -o PyBPMPD.so PyBPMPD.c

I'd appreciate any ideas on the problem. I'm rather stumped.

Thanks,
John


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
load_dynamic problem [ In reply to ]
John Fisher <jfisher@are.berkeley.edu> wrote:
: Hey folks,

: I'm having a bit of trouble loading a C extension into Python 1.5.2.
: I'm getting the error:

: Traceback (innermost last):
: File "<stdin>", line 1, in ?
: File "bpinter.py", line 9, in ?
: PyBPMPD = imp.load_dynamic('PyBPMPD', 'PyBPMPD.so')
: ImportError: ./PyBPMPD.so: undefined symbol: setdef

: setdef, not written by me, but called from inside PyBPMPD.c, is
: prototyped as:
: extern int setdef(bpmparam *);

: The module itself compiles without complaint with:
: gcc -I/usr/include/python1.5/ -shared -o PyBPMPD.so PyBPMPD.c

: I'd appreciate any ideas on the problem. I'm rather stumped.

: Thanks,
: John

John,

It sounds like "setdef" is in some library that you are not compiling
with. Or "setdef" was typed incorrectly in your code: resolving
symbols in shared objects is performed at runtime.

When compiling the shared object, you must include library being
referenced (the one that contains "setdef"). Preferably, that
library will be a static library (.a), or you would have to set
LD_LIBRARY_PATH (or LIBPATH on some systems) to point to the
correct location at run-time.

If the library is /usr/local/lib/libdef.so or /usr/local/lib/libdef.a,
then add "-L/usr/local/lib -ldef" to the gcc command you have.

Good luck,
-Arcege
load_dynamic problem [ In reply to ]
In article <qIWc3.329$Of3.76550@news.shore.net>,
"Michael P. Reilly" <arcege@shore.net> wrote:

> John,
>
> It sounds like "setdef" is in some library that you are not compiling
> with. Or "setdef" was typed incorrectly in your code: resolving
> symbols in shared objects is performed at runtime.
[...]
>
> Good luck,
> -Arcege

Thanks, Arcege. I was not aware that I needed to compile with the
libraries mentioned explicitly. Silly me though I could just #include
and have gcc look at the dirs. Anyway, I appreciate the pointer.

John


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.