I am getting an awkward error when creating a Node.js addon.
Error Message:
Error: /media/psf/fluxdb/build/Release/flux.node: undefined symbol: _ZN4flux20SinglyLinkedListWrapIiE11constructorE
I am trying to make a Template ObjectWrap to reuse with various types. The code compiles without error, but when I require the *.node file in JS, I get an undefined symbol error.
Below is my code for the Template class:
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));
}
}
};
}
Thank you for any help :)
我通过删除构造函数引用并直接使用tpl-> GetFunction()解决了该问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.