This topic is now archived and is closed to further replies.


Undefined reference to `_imp___Py_NoneStruct'

Recommended Posts

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");

    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]

Share this post

Link to post
Share on other sites
I found the answer thanks to (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:


_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("");


Share this post

Link to post
Share on other sites