node js addon方式调用 cpp

1、先报这个错,

UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in positio

后来发现项目路径中有中文,换成全英文路径

2、又报错

在此解决方案中一次生成一个项目。若要启用并行生成,请添加“/m”开关。
  democpp.cc
  win_delay_load_hook.cc
e:frontstudy odecppstudycaddon ode_modules ode-addon-api api.h(33): fatal error C1189: #error:  Exception support not detected.
      Define either NAPI_CPP_EXCEPTIONS or NAPI_DISABLE_CPP_EXCEPTIONS. (编译源文件 ..democpp.cc) [E:frontstudy odecppstudycaddonuild
democpp.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0BinMSBuild.exe` failed with exit co

在binding.gyp中 加入

'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],

3、官网文档

http://nodejs.cn/api/addons.html

官网附带的github直接用

https://github.com/nodejs/node-addon-examples

原文地址:https://www.cnblogs.com/cnchengv/p/13881729.html