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\nodecppstudy\caddon\node_modules\node-addon-api\napi.h(33): fatal error C1189: #error:  Exception support not detected.
      Define either NAPI_CPP_EXCEPTIONS or NAPI_DISABLE_CPP_EXCEPTIONS. (编译源文件 ..\democpp.cc) [E:\frontstudy\nodecppstudy\caddon\build
\democpp.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.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

 

posted @ 2020-10-26 22:16  cnchengv  阅读(627)  评论(0编辑  收藏  举报