• Advertisement


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

Undefined reference to `_imp___Py_NoneStruct'

This topic is 5342 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 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:


_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

  • Advertisement