Embedding Python in C, undefined symbol: PyExc_FloatingPointError

S

Simon Newton

Hi,

I've just starting out embedding Python in C and get the following error
when I try and import a module that in turn imports the math module.

ImportError: /usr/lib/python2.4/lib-dynload/math.so: undefined symbol:
PyExc_FloatingPointError

The module is as follows:

# begin script.py
import math

def fn(i):
print "i is %d" % i

# end script.py

and the C code is :

// start main.c
#include <Python.h>

int main(int argc, char *argv[]) {
PyObject *mymod, *fn, *strargs;

Py_Initialize();

mymod = PyImport_ImportModule("script");

if(mymod == NULL) {
PyErr_Print();
exit(1);
}

fn = PyObject_GetAttrString(mymod, "fn");

if(fn == NULL) {
PyErr_Print();
exit(1) ;
}

strargs = Py_BuildValue("(i)", 0);
PyEval_CallObject(fn, strargs);

Py_Finalize();
return 0;
}
// end main.c

Testing script.py by running python and importing the module works fine.
Commenting out the import math statement and import other modules (sys,
string etc) work fine.

The C program is being built like so:

gcc main.c -c -I-I/usr/include -I/usr/include -I/usr/include/python2.4
-I/usr/include/python2.4 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes
gcc main.o -L/usr/lib -lpthread -ldl -lutil
-lm /usr/lib/python2.4/config/libpython2.4.a -o main

I've tried the above on two machines, one Debian stable and the other
Debian testing. Same results on both.

It's like I'm missing a library or something, any ideas ?

Cheers,

Simon Newton
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Simon said:
gcc main.c -c -I-I/usr/include -I/usr/include -I/usr/include/python2.4
-I/usr/include/python2.4 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes
gcc main.o -L/usr/lib -lpthread -ldl -lutil
-lm /usr/lib/python2.4/config/libpython2.4.a -o main

I've tried the above on two machines, one Debian stable and the other
Debian testing. Same results on both.

It's like I'm missing a library or something, any ideas ?

No. You need to export the Python symbols from your executable to
extension modules. IOW, you need to pass

-Xlinker -export-dynamic

to the gcc invocation.

Regards,
Martin
 
S

Simon Newton

No. You need to export the Python symbols from your executable to
extension modules. IOW, you need to pass

-Xlinker -export-dynamic

to the gcc invocation.

Thanks Martin,

-export-dynamic fixed it.

Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top