473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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_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
Aug 17 '05 #1
2 2339
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

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
Aug 17 '05 #2
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

Aug 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: David McNab | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I'm working on a python plugin for someone else's code written in C. On the whole, I'm successfully embedding the python interpreter,...
2
by: Dennis Hore | last post by:
I'm trying to install Nick Patavalis' ppgplot package on Mac OS X 10.3 with python 2.3. I first sent this message to Nick, but he said he doesn't have any experience with the Mac platform. ...
0
by: Lars Kromann | last post by:
Hi I am trying to compile python 2.3.4 for AIX 5.2 but I ran into some problems. When I try to compile the build on the configure runs ok but make gives me the following error when i run: ...
0
by: Hugh Macdonald | last post by:
I've got a slight problem... and I'm stuck as to where to go with it... I'm running on Redhat7.2, using Python 2.2.2 I've got a compiled module that I wrote almost a year ago - it works fine,...
1
by: David Gutierrez | last post by:
Hello Everyone, I'm trying to install Python on an aix 4.3.3. but keep on getting a failed attempt with the following errors. ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock ld:...
0
by: ktelep | last post by:
I'm trying to build python 2.4.2 on AIX 5.3 with the IBM xlC compiler as per the notes in the AIX Readme file. Basically my make fails with the errors listed below. I'm calling configure with:...
1
by: Justin Johnson | last post by:
Hello, I'm trying to build Python 2.5.0 on AIX 5.3 using IBM's compiler (VisualAge C++ Professional / C for AIX Compiler, Version 6). I run configure and make, but makes fails with undefined...
0
by: Lane Brooks | last post by:
I am embedding python into a linux shared library (let's call it libembedpy.so). The main application loads this shared library dynamically using libdl and is not linked against libembedpy.so ...
4
by: DavidM | last post by:
Hi all, I'm embedding python in a C prog which is built as a linux shared lib. The prog is linked against libpython, and on startup, it calls Py_Initialize(). The prog imports a pure-python...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.