Extending python - undefined symbol error on import

ch424 alexander.chadwick at gmail.com
Fri Jul 22 11:49:38 EDT 2005


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




More information about the Python-list mailing list