node-gyp configure
node-gyp build
node-gyp rebuild --target=4.2.12 --arch= --dist-url=https://npm.taobao.org/mirrors/atom-shell
--arch=ia32 是32位
--arch=x64 是64位
--target指定electron版本号
--dist-url指定头文件下载地址,原答案这个值写的是https://atom.io/download/electron,国内的话不管用
node test.js
https://github.com/freezer333/nodecpp-demo.git
https://github.com/caoxiemeihao/node-addons-learn.git
- $ node-gyp configure:通过当前目录的 binding.gyp 生成项目文件,如 Makefile 等;
- $ node-gyp build:将当前项目进行构建编译,前置操作必须先 configure;
- $ node-gyp clean:清理生成的构建文件以及输出目录,说白了就是把目录清理了;
- $ node-gyp rebuild:相当于依次执行了 clean、configure 和 build;
- $ node-gyp install:手动下载当前版本的 Node.js 的头文件和库文件到对应目录。
使用nan
引入头文件 #include <nan.h>
由c库编写的库
使用napi
引入头文件 #include <node_api.h>
由c++库编写的库
使用node-addon-api
引入头文件 #include <napi.h>