0
创建Node.js插件时出现一个尴尬的错误。Node.js插件中的未定义符号
错误消息:
错误:/media/psf/fluxdb/build/Release/flux.node:未定义的符号:_ZN4flux20SinglyLinkedListWrapIiE11constructorE
我试图做一个模板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));
}
}
};
}
谢谢你的任何帮助:)