Embedding Python in C, undefined symbol: PyExc_FloatingPointError

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Newton

    #1

    Embedding Python in C, undefined symbol: PyExc_FloatingPointError

    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_FloatingP ointError

    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_Import Module("script" );

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

    fn = PyObject_GetAtt rString(mymod, "fn");

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

    strargs = Py_BuildValue(" (i)", 0);
    PyEval_CallObje ct(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


  • Martin v. Löwis

    #2
    Re: Embedding Python in C, undefined symbol: PyExc_FloatingP ointError

    Simon Newton wrote:[color=blue]
    > 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 ?[/color]

    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

    Comment

    • Simon Newton

      #3
      Re: Embedding Python in C, undefined symbol: PyExc_FloatingP ointError

      On Wed, 2005-08-17 at 09:52 +0200, "Martin v. Löwis" wrote:[color=blue]
      > Simon Newton wrote:[color=green]
      > > 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[/color]
      >
      > 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.[/color]

      Thanks Martin,

      -export-dynamic fixed it.

      Simon

      Comment

      Working...