473,770 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(PyOb ject *self, PyObject *args)
{
char *command;
int *secondarg;
// int sts;

if (!PyArg_ParseTu ple(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 SecondaryAddres s = 0; /* Sec addr of the device */

Device = ibdev( /* Create a unit descriptor handle */
BoardIndex, /* Board Index*/
PrimaryAddress, /* Device pri addr */
SecondaryAddres s, /* 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('gpib module',
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 "ImportErro r: /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 13502
ch424 wrote:
However, when I open up the python command line, and type "from gpib
import *" or "import gpib" I get "ImportErro r: /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 "ImportErro r: /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('gpib module',
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
3026
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 without any imports. However when I add an "import urllib" inside the Python script to be imported through my C++ application then the import fails: Traceback (most recent call last):
0
1739
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, and I've never had any problems with it... I also did an extension to a plugin (Shake) using Python, so the plugin loads a python module and calls various functions in there.... all in all, fine - I thought I had my head around the system, and...
2
4455
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 factory in the following way: static MyObject myInstance;
10
8058
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 -v abc.cpp //that's how you "make" in Matlab, and that's what was called: -> g++ -c ... abc.cpp -> gcc -c ... /usr/local/matlab701/extern/src/mexversion.c
4
4021
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: 1. the sources compiled with gcc 4.1.2 crash with illegal instruction error: (running my application)
0
4382
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: "PythonHandler edit::handler" Traceback (most recent call last):
1
4912
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 symbols. See the output from configure and make below. svnadm /svn/build/python-2.5.0>env CC=cc CXX=xlC ./configure --prefix=$base_dir \ checking MACHDEP... aix5
1
2761
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: PyObject_SelfIter I have python-2.3.3-88.9.x86 installed on my machine. Why is this error coming? how can I resolve this undefined symbol? Do I need to import anything before this?
7
4090
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 the Numeric Python (numpy) package. I need to run my code on a particular machine made available by my university, which does not have numpy and will not be getting it. So I am trying to write my own mini-wrapper for MPI in C to extend my Python...
0
9617
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10257
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10037
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7456
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.