window
- 以管理员身份运行powerShell/cmd,然后安装vs2017编译器以及python2.7.下面的指令会帮你下载安装。
npm install --global --production windows-build-tools
安装完毕,测试,控制台node-gyp listnpm install -g node-gyp

linux
一般自带python2.7 或者GCC .所以只要npm install -g node-gyp
小试牛刀。编写简单的c++扩展
准备binding.gyp
{"targets":[{"target_name":"addon","sources":["test.cc"]}]}
准备test.cc
#include <node.h>namespace demo{using v8::FunctionCallbackInfo;using v8::Isolate;using v8::Local;using v8::Object;using v8::String;using v8::Value;using v8::Number;void ExportMethodTest(const FunctionCallbackInfo<Value>& args){Isolate* isolate = args.GetIsolate();args.GetReturnValue().Set(String::NewFromUtf8(isolate, "hello world"));}void init(Local<Object> exports){NODE_SET_METHOD(exports, "hello", ExportMethodTest);}NODE_MODULE(addon, init)}
准备test.js
const addon = require('./build/Release/addon.node');console.log(addon.hello());
首先binding.gyp目录执行 node-gyp build/rebuild详细使用,能看到build目录生成。
之后node test.js
