Node.js插件中未定义的符号

Undefined Symbol in Node.js Addon

本文关键字:符号 未定义 js 插件 Node      更新时间:2023-10-16

我在创建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()来解决它。