1、安装运行环境
npm install -g windows-build-tools
####
##建议使用cnpm(cnpm install -g windows-build-tools)
####
2、该命令会自动安装,python 及 visio studioC++等环境
3、编写C++应用程序,调用
1)创建工作目录文件夹(test)
1.1在test目录中创建test.cc 和binding.gyp
CMD命令中:
第一步:执行 node-gyp configure
第二步:执行 node-gyp build
第三步:node app
C++代码示例:
#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)
}
binding.gyp示例:
{
'targets':[
{
'target_name':'hello',
'sources':['hello.cc'],
}]
}
app.js示例:
const addon = require('./build/Release/hello');
console.log(addon.hello()); // 'world'