473,416 Members | 1,547 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,416 software developers and data experts.

Extending python - undefined symbol error on import

Hi there,

I'm using Python 2.4.1 on Ubuntu Linux, and I'm having problems
extending python in C:

The C code is below:

#include <Python.h>
#include "ni488.h"

static PyObject *
gpib_hello(PyObject *self, PyObject *args)
{
char *command;
int *secondarg;
// int sts;

if (!PyArg_ParseTuple(args, "|si", &command, &secondarg)) //both
arguments are optional
return NULL;

// TODO: Inserting code for the function here!

// FROM HERE
int Device = 0; /* Device unit descriptor*/
int BoardIndex = 0; /* Interface Index*/

int PrimaryAddress = 13; /* Pri addr of the device */
int SecondaryAddress = 0; /* Sec addr of the device */

Device = ibdev( /* Create a unit descriptor handle */
BoardIndex, /* Board Index*/
PrimaryAddress, /* Device pri addr */
SecondaryAddress, /* Device sec addr*/
T10s, /* Timeout setting = 10 seconds */
1, /* Assert EOI line at end of write */
0); /* EOS termination mode */

// TO HERE IS THE GPIB STUFF

return Py_BuildValue("s", "hello world");
}
static PyMethodDef gpibMethods[] = {
/* ... */
{"hello", gpib_hello, METH_VARARGS,
"Get Hello world returned."},
/* ... */
{NULL, NULL, 0, NULL} /* Sentinel */
};

PyMODINIT_FUNC
initgpib(void)
{
(void) Py_InitModule("gpib", gpibMethods);
}

As you can see, it's the standard "spammodule" example, with "spam"
replaced with "gpib", an extra include (ni488) and that block of code
added. This compiles absolutely faultlessly (even no warnings!) using
the python script:

from distutils.core import setup, Extension

module1 = Extension('gpibmodule',
sources = ['gpibmodule.c'])

setup (name = 'gpibmodule',
version = '0.0.1',
description = 'This is the gpib package',
ext_modules = [module1])

However, when I open up the python command line, and type "from gpib
import *" or "import gpib" I get "ImportError: /usr/.../gpibmodule.so:
undefined symbol: ibdev" -- but I know it's defined in the ni488.h
file, especially as I can use this code from actual C programs without
problems. The ni488.h file in in the right place to be used for C
compilation.

So, the question is, what did I type wrong? Why is python examining
that c function embedded in another, surely it should only be
interested in providing arguments and getting returned values, and what
the c function does is its own bussiness?

Any help would be hugely appreceated!

Thanks

Alex

Jul 22 '05 #1
3 13468
ch424 wrote:
However, when I open up the python command line, and type "from gpib
import *" or "import gpib" I get "ImportError: /usr/.../gpibmodule.so:
undefined symbol: ibdev" -- but I know it's defined in the ni488.h
file, especially as I can use this code from actual C programs without
problems. The ni488.h file in in the right place to be used for C
compilation.


I guess ibdev is *declared* in ni488.h and you'll have to add the lib
where it is *defined*. You'll probably have to add a
libraries = ['gpip']
to setup.py.

Daniel
Jul 22 '05 #2
ch424 wrote:
[snip]
However, when I open up the python command line, and type "from gpib
import *" or "import gpib" I get "ImportError: /usr/.../gpibmodule.so:
undefined symbol: ibdev" -- but I know it's defined in the ni488.h
file, especially as I can use this code from actual C programs without
problems. The ni488.h file in in the right place to be used for C
compilation.

So, the question is, what did I type wrong? Why is python examining
that c function embedded in another, surely it should only be
interested in providing arguments and getting returned values, and what
the c function does is its own bussiness?


Daniel has already given you what to do to get over your immediate
problem. I'd just like to add a couple of mindset adjustments to get you
over the next few stiles.

The message ".... gpibmodule.so: undefined symbol: ibdev" is being
reported by Python, but this problem is detected by an operating-system
specific loader. What it is trying to tell you is that gpibmodule.so
contains a call to a function named ibdev, but the loader can't find
ibdev. This is nothing to do with extending Python; if you had written a
stand-alone program in C, and made the same mistake [not providing the
name of the library containing ibdev], you would have got a similar
message either from the linker or later from the loader.

Neither Python nor the loader is "examining" ibdev, the loader can't
even find it, and Python has no way of knowing that it exists (and
doesn't and shouldn't care) even if the loader could find it! It is the
job of *your* code to interface with the ibdev routine.

Another slant on all this: the problem doesn't exist on the boundary
between Python and your extension module; it exists on the boundary
between your module and a 3rd party function called by your module.

HTH,
John
Jul 22 '05 #3
Sweet! It works! *dances*

Thank you so much -- and for the explanation! For anyone searching for
this, I had to change the respective lines to:

module1 = Extension('gpibmodule',
libraries = ['gpibapi'],
sources = ['gpibmodule.c'])

just as Daniel said.

Thanks again,

Alex

Jul 25 '05 #4

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

Similar topics

1
by: Andreas Jung | last post by:
I am trying to embed Python within a C++ application (Linux, Python2.3.4). I am using the example from the example from the "Embeding and Extending" docs. This works fine importing a simple module...
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,...
2
by: Manuel Maria Diaz Gomez | last post by:
Hi Everybody, maybe you can give me a hint about this. I implemented a simple singleton Factory that will (among other things) keep a registry of objects. Objects register themself in the...
10
by: eugene | last post by:
I'm trying to compile and run some c++ code to be called from Matlab (mex file) and I'm getting "Invalid MEX-file ... undefined symbol" error. Anybody knows where to look for solution? >>mex...
4
by: Mathias Waack | last post by:
Hi, I've embedded python into a legacy application. It works - most of the time. In some special situations the app crashes executing the "import random". There are two different situations: ...
0
by: çÌÏÔÏ× áÒÔÅÍ | last post by:
Hello! I'm trying to install the web application written with Python, and have the trouble with module math.so: # lwp-request http://localhost/site/code/edit.py Mod_python error:...
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...
1
by: grbgooglefan | last post by:
I am importing cStringIO module in my PythonC++ embedded program. The import is failing with the following error: ImportError: /usr/lib/python2.3/lib-dynload/cStringIO.so: undefined symbol:...
7
by: Spectrum | last post by:
I am writing some Python code using the Message Passing Interface (MPI), an API used in parallel computing. There exist a number of Python implementations of MPI, but apparently they all rely on...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.