Embedding Python in C, undefined symbol: PyExc_FloatingPointError

2005-08-16 Thread 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 

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


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding Python in C, undefined symbol: PyExc_FloatingPointError

2005-08-17 Thread Simon Newton
On Wed, 2005-08-17 at 09:52 +0200, "Martin v. Löwis" wrote:
> Simon Newton wrote:
> > 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
> 
> 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

-- 
http://mail.python.org/mailman/listinfo/python-list