Node.js插件中未定义的符号
Undefined Symbol in Node.js Addon
我在创建Node.js插件时遇到了一个尴尬的错误。
错误消息:
错误:/media/psf/fluxdb/build/Release/flux.node:未定义符号:_ZN4flux20SinglyLinkedListWrapIE11constructorE
我正在尝试制作一个模板ObjectWrap,以便与各种类型一起重用。代码编译没有错误,但当我需要JS中的*.node文件时,我会得到一个未定义的符号错误。
下面是我的模板类代码:
using namespace node;
using namespace v8;
namespace flux {
template <typename T>
class SinglyLinkedListWrap : public ObjectWrap {
public:
static void Init(Handle<Object> exports, const char *symbol) {
// Prepare constructor template
Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
tpl->SetClassName(String::NewSymbol(symbol));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
// exports
constructor = Persistent<Function>::New(tpl->GetFunction());
exports->Set(String::NewSymbol(symbol), constructor);
}
protected:
SinglyLinkedList<T> *list_;
private:
SinglyLinkedListWrap() {
list_ = new SinglyLinkedList<T>();
}
~SinglyLinkedListWrap() {
delete list_;
}
SinglyLinkedList<T> *list() {
return list_;
}
static Persistent<Function> constructor;
// new SinglyLinkedList or SinglyLinkedList() call
static Handle<Value> New(const Arguments& args) {
HandleScope scope;
if (args.IsConstructCall()) {
// Invoked as constructor: `new SinglyLinkedList(...)`
SinglyLinkedListWrap<T> *obj = new SinglyLinkedListWrap<T>();
obj->Wrap(args.This());
return scope.Close(args.This());
} else {
// Invoked as plain function `SinglyLinkedList(...)`, turn into construct call.
const int argc = 1;
Local<Value> argv[argc] = {args[0]};
return scope.Close(constructor->NewInstance(argc, argv));
}
}
};
}
感谢您的帮助:)
我通过删除构造函数引用并直接使用tpl->GetFunction()来解决它。
相关文章:
- vscode g++链路故障:体系结构x86_64的未定义符号
- 在 Mac 上使用 CMAKE 将 FFTW 和 FFTWPP 链接到项目中时未定义的符号
- 在C++中使用内联方法时出现未定义的符号错误
- 引擎节点:未定义的符号:_ZTV6Config
- 未定义的引用,尽管存在符号,但 std::experimental::可选
- 体系结构x86_64的未定义符号:std:terminate(),typeinfo,运算符delete[],运算符new
- Windows 链接器是否使用 LoadLibrary 解析 DLL 中未定义的符号?
- C++ 中 dlsym 的未定义符号
- MacOS 上的 Xcode 11 项目不在一个函数中使用 sin 和 cos:未定义的符号"___sincosf_stret"
- 仅在 MacOS 上析构函数的未定义符号
- OSX clang++:用于 cpp 文件中显式实例化模板的体系结构x86_64的未定义符号
- PCL 出错:体系结构x86_64 @pcl的未定义符号
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 从 C++ 到 Python 的 SWIG:未定义的符号导入问题
- 使用静态变量未解析的外部符号/未定义的引用时出错
- 无法导出mexfunction:符号未定义的collect.exe2.exe:错误:ld返回1退出状态
- 模板生成错误:体系结构的符号未定义 x86_64:
- 继承-符号未定义
- __next_prime符号未定义
- 错误:对cv:: videoccapture::~ videoccapture()的引用符号未定义,命令行中缺少DSO