簡體   English   中英

Node.js插件中的未定義符號

[英]Undefined Symbol in Node.js Addon

創建Node.js插件時出現了一個尷尬的錯誤。

錯誤信息:

錯誤:/media/psf/fluxdb/build/Release/flux.node:未定義的符號:_ZN4flux20SinglyLinkedListWrapIiE11constructorE

我試圖使一個模板ObjectWrap可以重復使用各種類型。 代碼編譯沒有錯誤,但是當我在JS中需要* .node文件時,我得到了未定義的符號錯誤。

以下是我的Template類代碼:

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()解決了該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM