node.js加载项上未定义的符号
我正在尝试创建一些node.js插件。在插件中,我调用了一个静态库。一切都可以编译,但当我从javascript调用我的加载项函数时,我得到以下结果:node.js加载项上未定义的符号,node.js,static-libraries,add-on,embedded-v8,Node.js,Static Libraries,Add On,Embedded V8,我正在尝试创建一些node.js插件。在插件中,我调用了一个静态库。一切都可以编译,但当我从javascript调用我的加载项函数时,我得到以下结果: module.js:356 Module._extensions[extension](this, filename); ^ Error: /home/.../Projects/NodeAddonComLibTest/build/Debug/addon.node: undefined sy
module.js:356
Module._extensions[extension](this, filename);
^
Error: /home/.../Projects/NodeAddonComLibTest/build/Debug/addon.node: undefined symbol: _Z6ctest1Pi
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/.../Projects/NodeAddonComLibTest/doTest.js:1:75)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <node.h>
#include <v8.h>
using namespace v8;
using namespace std;
void ctest1(int *);
Handle<Value> setPort(const Arguments& args){
HandleScope scope;
if (args.Length() != 1) {
ThrowException(Exception::TypeError(String::New("Wrong number of arguments.")));
return scope.Close(Undefined());
}
// =========================
printf("Calling static lib...\n");
int x=0;
ctest1(&x);
printf("Val c=%d\n", x);
// =========================
return scope.Close(Number::New(args[0]->NumberValue()));
}
void Init(Handle<Object> exports) {
exports->Set(String::NewSymbol("show"), FunctionTemplate::New(setPort)->GetFunction());
}
NODE_MODULE(addon, Init)
module.js:356
模块扩展名[扩展名](此,文件名);
^
错误:/home/../Projects/NodeAddonComLibTest/build/Debug/addon.node:未定义的符号:_Z6ctest1Pi
在Module.load(Module.js:356:32)
在Function.Module.\u加载(Module.js:312:12)
at Module.require(Module.js:364:17)
根据需要(模块js:380:17)
反对。(/home/../Projects/NodeAddonComLibTest/doTest.js:1:75)
在模块处编译(Module.js:456:26)
在Object.Module.\u extensions..js(Module.js:474:10)
在Module.load(Module.js:356:32)
在Function.Module.\u加载(Module.js:312:12)
位于Function.Module.runMain(Module.js:497:10)
我的加载项代码如下所示:
module.js:356
Module._extensions[extension](this, filename);
^
Error: /home/.../Projects/NodeAddonComLibTest/build/Debug/addon.node: undefined symbol: _Z6ctest1Pi
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/.../Projects/NodeAddonComLibTest/doTest.js:1:75)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <node.h>
#include <v8.h>
using namespace v8;
using namespace std;
void ctest1(int *);
Handle<Value> setPort(const Arguments& args){
HandleScope scope;
if (args.Length() != 1) {
ThrowException(Exception::TypeError(String::New("Wrong number of arguments.")));
return scope.Close(Undefined());
}
// =========================
printf("Calling static lib...\n");
int x=0;
ctest1(&x);
printf("Val c=%d\n", x);
// =========================
return scope.Close(Number::New(args[0]->NumberValue()));
}
void Init(Handle<Object> exports) {
exports->Set(String::NewSymbol("show"), FunctionTemplate::New(setPort)->GetFunction());
}
NODE_MODULE(addon, Init)
#包括
#包括
#包括
#包括
#包括
使用名称空间v8;
使用名称空间std;
无效ctest1(int*);
句柄设置端口(常量参数和参数){
手镜镜;
如果(参数长度()!=1){
ThroweException(Exception::TypeError(String::New(“参数数目错误”));
返回scope.Close(未定义());
}
// =========================
printf(“调用静态库…\n”);
int x=0;
ctest1&x;
printf(“Val c=%d\n”,x);
// =========================
返回scope.Close(Number::New(args[0]->NumberValue());
}
void Init(句柄导出){
exports->Set(字符串::NewSymbol(“show”),FunctionTemplate::New(setPort)->GetFunction();
}
节点_模块(加载项,初始化)
有人能帮忙吗
谢谢你的空ctest1(int*);必须用外部“C”
声明它: