节点:符号查找错误:,未定义符号:_ZN4demo3sumEii

我正在创build一个C ++插件,我想使用一个静态库。 我有一个图书馆libarith这只是简单的加法。

-libarith.a -hello.cc -hello.js 

我的binding.gyp文件如下:

 { "targets": [ { "target_name": "addon", "sources": [ "hello.cc" ], "libraries": [ "-/home/folder/api/addon/libarith.a" ], "cflags!": [ "-fno-exceptions" ], "cflags": [ "-std=c++11" ], "cflags_cc!": [ "-fno-exceptions" ] } ] } 

当我编译我的hello.cc编译好。 但是,当我运行我的插件,它给出了以下错误:

node:symbol lookup error: /home/folder/api/addon/build/Release/addon.node: undefined symbol: _ZN4demo3sumEii.

我是新来的插件,一个帮助将非常感激。

代码片段: – libarith.a包含:

 int sum(int a ,int b){ return a+b; } 

// hello.cc

 #include <node.h> #include <vector> #include <iostream> #include <v8.h> using namespace std; using namespace v8; namespace demo { using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; using v8::Object; using v8::String; using v8::Value; void newmethod(const FunctionCallbackInfo<Value>& args) { extern int sum(int,int); Isolate* isolate = args.GetIsolate(); double abc= sum(4,5); Local<Number> newnumber =Number::New(isolate,abc); v8::String::Utf8Value r(args[1]); std::string rst(*r); Local<String> first = String::NewFromUtf8(isolate, "firstargument"); Local<String> second = String::NewFromUtf8(isolate, "secondargument"); Local<Object> newobj= Object::New(isolate); newobj->Set(first,String::NewFromUtf8(isolate, *s)); newobj->Set(second,newnumber); args.GetReturnValue().Set(newobj); } void init(Local<Object> exports) { NODE_SET_METHOD(exports, "newmethod", newmethod); } NODE_MODULE(addon, init) } 

//hello.js

 const addon = require('./build/Release/addon'); var ss = "helloo"; var samplestring = "It is not a sample string"; console.log(addon.newmethod(samplestring, ss)); 

编辑: – 解决scheme的工作如下。 我试图为库创build一个单独的目录,它工作正常。

它说,它找不到声明(执行.h )。 我认为你给你的图书馆指出了错误的方向。 有两个解决scheme:

  1. 写完整的目录到您的库在~/whereItIsLocated ,在我的情况下是~/CLionProjects/node-player-core/PlayerCore/lib/x64/yourLibraryName.a
  2. 如果以前的解决scheme没有帮助,则可以将库复制到/usr/lib 。 你可以用sudo cp ~/whereLibraryLocated /usr/lib