extending python: c++ problem

Torsten Hörmann torsten.hoermann at telekom.de
Thu Mar 30 15:59:52 CEST 2000


Does anyone know about the following problem and have a solution?
I've written a python extension using c++. No Problems with msvc, but on
HPUX with aCC. When importing the <iostream.h>, the python interpreter can
not find the "initmod" function in the created lib. Error message:

>>> import mod
Traceback (innermost last):
  File "<stdin>", line 1, in ?
ImportError: dynamic module does not define init function (initmod)
>>>

For compling and linking i have used the makefile.pre.in from the
python-distribution (no errors/warnings while building the mod.sl)
My Lib is a little more complex, but the following small lib demonstrates
this problem (it is a example from earlier posting in this newsgroup):

/*testmod.cpp*/
#include <Python.h>

#include <iostream.h> // this include causes the error message; without,
there is no problem

static PyObject * mod_getsub(PyObject * self, PyObject * args)
{
    printf("worked\n");
    Py_INCREF(Py_None);
    return Py_None;
}

static PyMethodDef modMethods[] = {
    {"work", mod_getsub, METH_VARARGS},
    {NULL, NULL}
};


extern "C"
void initmod()
{
   (void) Py_InitModule ("mod", modMethods);
}

I have spend some hours with trying some ways to avoid this include, but now
i dont have any more ideas.
Can anyone help me????

Thanks Torsten






More information about the Python-list mailing list