【问题标题】:Undefined Symbol in Node.js AddonNode.js 插件中的未定义符号
【发布时间】:2014-10-27 15:50:57
【问题描述】:

我在创建 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));
            }
        }
    };

}

感谢您的帮助:)

【问题讨论】:

    标签: c++ node.js v8


    【解决方案1】:

    我通过删除构造函数引用并直接使用 tpl->GetFunction() 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多