【发布时间】:2016-08-09 16:15:12
【问题描述】:
在 NodeJS 中,我正在为 C 中的共享对象构建一个接口。我有以下代码:
#include <node.h>
#include "libcustom_encryption.h"
namespace demo {
using v8::Exception;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Number;
using v8::Object;
using v8::String;
using v8::Value;
//
// This is the implementation of the "add" method
// Input arguments are passed using the
// const FunctionCallbackInfo<Value>& args struct
//
void DeviceGetVersion(const FunctionCallbackInfo<Value>& args)
{
char ver[10] = {0};
unsigned int ver_size = 0;
device_get_version(ver, ver_size);
Isolate* isolate = args.GetIsolate();
//
// 1. Save the value in to a isolate thing
//
Local<Value> str = String::NewFromUtf8(isolate, "Test");
//
// 2. Set the return value (using the passed in
// FunctionCallbackInfo<Value>&)
//
args.GetReturnValue().Set(str);
}
void Init(Local<Object> exports)
{
NODE_SET_METHOD(exports, "devicegetversion", DeviceGetVersion);
}
NODE_MODULE(addon, Init)
}
-
node-gyp configure:有效 -
node-gyp build:有效 -
LD_LIBRARY_PATH=libs/ node index.js: 不行
我收到以下错误:
node: symbol lookup error: /long_path/build/Release/app.node: undefined symbol: _Z18device_get_versionPcS_Phj
当函数被调用时,它会被添加随机字符。我假设这是随机数据,是内存中的一些噪音。看起来好像调用函数的刹车尺寸比它应该的大。
我没有混合 C++ 和 C 的经验,我很想听听正在发生的事情的解释。
技术规格:
- GCC 版本:gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
- NodeJS 版本:v6.2.0
【问题讨论】: