Search code examples
pythonnode.jspython-2.7v8cpython

CPython - Compile dails, PyDateTime_FromTimestamp not declared?


I'm writing a V8 add-on to convert javascript objects to python, and vice-versa. I'm able to convert all sorts of types, but PyDateTime_FromTimestamp (which is specified as existing in the cpython docs: https://docs.python.org/2/c-api/datetime.html#c.PyDateTime_FromTimestamp) is apparently undefined, causing compilation to fail.

../src/py_object_wrapper.cc:189:13: error: use of undeclared identifier 
'PyDateTime_FromTimestamp'
        return PyDateTime_FromTimestamp(value->NumberValue());

Anybody know what's going on?


Solution

  • Since you haven't given us enough information to debug anything, I'm going to take a wild guess at the most likely problem.

    Notice that at the top of the documentation you linked to it says:

    Various date and time objects are supplied by the datetime module. Before using any of these functions, the header file datetime.h must be included in your source (note that this is not included by Python.h), and the macro PyDateTime_IMPORT must be invoked, usually as part of the module initialisation function. The macro puts a pointer to a C structure into a static variable, PyDateTimeAPI, that is used by the following macros.

    If you just forgot the macro, this would compile but then crash at runtime, as PyDateTimeAPI will be NULL.

    But if you forgot to #include the datetime.h, that would cause exactly what you're seeing.