CPython编译dails,PyDateTime_FromTimestamp没有声明?

2024-05-14 08:15:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个V8插件来将javascript对象转换为python,反之亦然。我能够转换各种类型,但是PyDateTime_FromTimestamp(在cpython文档中被指定为存在于https://docs.python.org/2/c-api/datetime.html#c.PyDateTime_FromTimestamp)显然没有定义,导致编译失败。在

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

有人知道怎么回事吗?在


Tags: 对象文档httpsorg插件apidocsdatetime
1条回答
网友
1楼 · 发布于 2024-05-14 08:15:33

既然您没有给我们足够的信息来调试任何东西,我将对最有可能的问题进行疯狂的猜测。在

注意,在documentation you linked to的顶部,它说:

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.

如果您忘记了宏,这将编译,但在运行时崩溃,因为PyDateTimeAPI将为空。在

但是如果你忘了#include这个datetime.h,那将导致你所看到的一切。在

相关问题 更多 >

    热门问题