Saturday 8 June 2013

#include doesn't work under Cygwin

#include <Python.h> doesn't work under Cygwin

Tried compiling the example from the beginning of this Python documentation article with gcc in Cygwin. My code:
#include <Python.h>

static PyObject *
spam_system(PyObject *self, PyObject *args)
{
    const char *command;
    int sts;

    if (!PyArg_ParseTuple(args, "s", &command))
        return NULL;
    sts = system(command);
    return PyLong_FromLong(sts);
}
However, when trying to compile, gcc gives me the following error:
In file included from /usr/include/Python.h:77:0,
                 from test.c:1:
/usr/include/longobject.h:77:26: error: expected '=', ',', ';', 'asm' or '__attr
ibute__' before 'PyLong_AsLongLong'
/usr/include/longobject.h:78:35: error: expected '=', ',', ';', 'asm' or '__attr
ibute__' before 'PyLong_AsUnsignedLongLong'
/usr/include/longobject.h:79:35: error: expected '=', ',', ';', 'asm' or '__attr
ibute__' before 'PyLong_AsUnsignedLongLongMask'
/usr/include/longobject.h:80:26: error: expected '=', ',', ';', 'asm' or '__attr
ibute__' before 'PyLong_AsLongLongAndOverflow'
Any ideas?
Update:
Apparently this is caused by PY_LONG_LONG expanding to __int64, which is not defined unless I include windows.h before Python.h. However, I don't see why that should be necessary, and it violates the following rule from the linked article: "Since Python may define some pre-processor definitions which affect the standard headers on some systems, you must include Python.h before any standard headers are included."
Is there any way to avoid having to include windows.h?

No comments:

Post a Comment