我正在使用此https://github.com/nodejs/node-addon-api/blob/master/doc/bigint.md文档作为从c++返回bigint的引用,但出现以下错误:
error: ‘BigInt’ in namespace ‘Napi’ does not name a type
Napi::BigInt HelloWrapped(const Napi::CallbackInfo& info);
这是我的源代码:
#include <napi.h>
#include "bigintexample.h"
std::int64_t bigintexample::hello() {
return 1234;
}
Napi::BigInt bigintexample::HelloWrapped(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::BigInt returnValue = Napi::BigInt::New(env, bigintexample::hello());
return returnValue;
}
Napi::Object InitAll(Napi::Env env, Napi::Object exports) {
exports.Set("hello", Napi::Function::New(env, bigintexample::HelloWrapped));
return exports;
}
NODE_API_MODULE(NODE_GYP_MODULE_NAME, InitAll)
在napi.h中,仅当NAPI_VERSION定义大于2147483646时,BigInt功能才可用。当我将NAPI_VERSION定义设置为大于2147483646的数字时,会收到以下错误消息
/home/user/bigint-napi/node_modules/node-addon-api/napi-inl.h:573:24: error: ‘napi_create_bigint_int64’ was not declared in this scope
napi_status status = napi_create_bigint_int64(env, val, &value);
最佳答案
通过添加定义来解决它:NAPI_EXPERIMENTAL并删除NAPI_VERSION定义