gpt4 book ai didi

python - CPython - 编译 dails,PyDateTime_FromTimestamp 未声明?

转载 作者:太空宇宙 更新时间:2023-11-03 18:12:20 26 4
gpt4 key购买 nike

我正在编写一个 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());

有人知道这是怎么回事吗?

最佳答案

由于您没有向我们提供足够的信息来调试任何内容,因此我将对最有可能的问题进行大胆猜测。

请注意 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 将为 NULL。

但是,如果您忘记#include datetime.h,那么就会导致您所看到的情况。

关于python - CPython - 编译 dails,PyDateTime_FromTimestamp 未声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25694570/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com