环境:Ubuntu虚拟机 场景描述:按照nodejs文档中的C++插件部分运行node-gyp报错。代码如下: hello.cc
#include <node.h>
namespace demo {
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;
void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
}
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
NODE_MODULE(addon, init)
}
hello.js
const addon = require('./build/Release/addon');
console.log(addon.hello());
编译好之后,运行hello.js报如下错误