引擎节点:未定义的符号:_ZTV6Config
engine.node: undefined symbol: _ZTV6Config
我已经编写了我的第一个Node.JSN-API 插件,但它因日志而崩溃:
internal/modules/cjs/loader.js:718
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: /home/d/Projects/engine/build/Release/engine.node: undefined symbol: _ZTV6Config
at Object.Module._extensions..node (internal/modules/cjs/loader.js:718:18)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/home/d/Projects/engine/index.js:1:78)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
下面是我的代码:wrapper.h:
#include <napi.h>
#include "types.hpp"
using namespace std;
class Config: public Napi::ObjectWrap<Config> {
config_t _cfg;
public:
explicit Config(const Napi::CallbackInfo &info);
~Config();
static Napi::FunctionReference constructor;
static Napi::Object Init(Napi::Env &env, Napi::Object &exports);
config_t Get();
private:
Napi::Value GetTimeAccuracy(const Napi::CallbackInfo &info);
void SetTimeAccuracy(const Napi::CallbackInfo &info, const Napi::Value &value);
};
wrapper.cc:
Config::Config(const Napi::CallbackInfo &info): Napi::ObjectWrap<Config>(info) {
}
Napi::Object Config::Init(Napi::Env &env, Napi::Object &exports) {
// This method is used to hook the accessor and method callbacks
Napi::Function func = DefineClass(env, "Config", {
InstanceAccessor("timeAccuracy", &Config::GetTimeAccuracy, &Config::SetTimeAccuracy)
});
// Create a peristent reference to the class constructor. This will allow
// a function called on a class prototype and a function
// called on instance of a class to be distinguished from each other.
constructor = Napi::Persistent(func);
// Call the SuppressDestruct() method on the static data prevent the calling
// to this destructor to reset the reference when the environment is no longer
// available.
constructor.SuppressDestruct();
exports.Set("Config", func);
return exports;
}
Napi::FunctionReference Config::constructor;
config_t Config::Get() {
return _cfg;
}
Napi::Value Config::GetTimeAccuracy(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
return Napi::Number::New(env, _cfg.time_accuracy);
}
void Config::SetTimeAccuracy(const Napi::CallbackInfo &info, const Napi::Value &value) {
_cfg.time_accuracy = value.As<Napi::Number>().FloatValue();
}
engine.cc:
#include <napi.h>
#include "wrapper.h"
Napi::Object init(Napi::Env env, Napi::Object exports) {
Config::Init(env, exports);
return exports;
}
NODE_API_MODULE(engine, init);
binding.gyp:
{
"targets": [{
"cflags_cc": ["-std=c++17"],
"include_dirs": [
"<!@(node -p "require('node-addon-api').include")"
],
"target_name": "engine",
"sources": [
"wrapper.cc",
"engine.cc",
"types.cpp",
],
"defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"]
}]
}
当我重建项目时,它没有任何错误。在我写一个简单的Hello,World!之前,我刚刚注册了打印文本的功能,并且一切运行良好。但是现在当我尝试将我的模块导入为const engine = require('./build/Release/engine.node');
时,我遇到了错误(见上文(。
当我得到我的模块寄存器但在 Node 之后.JS找不到Config
的实现。
我该如何解决它?
_ZTV6Config
是vtable for Config
的混乱名称。
令人困惑的是,这实际上是由于缺少Config
析构函数方法的实现引起的。
编译器在查找析构函数定义的同一转换单元中定义 vtable。
相关文章:
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 将无符号char*转换为std::istream*C++
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- vscode g++链路故障:体系结构x86_64的未定义符号
- 从矢量<无符号字符>转换为字符* 包括垃圾数据
- 如何理解将半精度指针转换为无符号长指针和相关的内存对齐
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 使用gcc从静态链接的文件中查找可选符号
- C++中无符号字符溢出
- 使用无符号字符数组有效存储内存
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- VC++本机单元测试,找不到调试符号
- 为什么我必须在C++中添加一个赋值符号来声明一个数组
- 检查TCHAR数组输入是否为带符号整数C++
- 用符号版本替换对函数的所有调用
- 未解析的外部符号_MsiLocateComponentW@12.
- 如何打印boost多精度128位无符号整数
- C++模板函数,用于比较任何无符号整数和有符号整数
- 在 Mac 上使用 CMAKE 将 FFTW 和 FFTWPP 链接到项目中时未定义的符号