#### Archived

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

# Undefined reference to _imp___Py_NoneStruct'

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

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

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]

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

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]

• ### Forum Statistics

• Total Topics
628642
• Total Posts
2983998

• 9
• 9
• 10
• 21
• 20