Undefined reference to `_imp___Py_NoneStruct'

Started by
0 comments, last by teamonkey 20 years, 9 months ago
Hi I get this message when I create a Python embedded function in C++ that doesn''t return anything (that it, it returns Py_NONE). For example:

static PyObject* emb_hello(PyObject *self, PyObject *args) {
    printf("Hello World!\n");

    Py_INCREF(Py_None);
    return Py_None;
} 
I get two identical linking errors that correspond to the two last lines of that function:

main.o(.text+0x1f):main.cpp: undefined reference to `_imp___Py_NoneStruct''
main.o(.text+0x26):main.cpp: undefined reference to `_imp___Py_NoneStruct''
 
Does anyone know what''s going on here? I''m using Dev-C++ with Python 2.2.3. Cheers [teamonkey]
[teamonkey] [blog] [tinyminions]
Advertisement
I found the answer thanks to help@python.org (because as soon as I clicked "send" I found it). I''ll give it here in case anyone else has the same problem.

It''s actually in the Python FAQ, section 8.16. Particularly this bit:

quote:
Py_INCREF(Py_None);
_resultobj = Py_None;
return _resultobj;

Alas, Py_None is a macro that expands to a reference to a complex data structure called _Py_NoneStruct inside python##.dll. Again, this code will fail in a mult-compiler environment. Replace such code by:

return Py_BuildValue("");


[teamonkey]
[teamonkey] [blog] [tinyminions]

This topic is closed to new replies.

Advertisement