使用node-gyp构建本机模块(尝试对我的cpp文件使用ffmpeg),它会引发异常:错误LNK2001无法解析的外部符号
示例代码:
index.cpp
#include <node.h>
extern "C"
{
#include "demo.h"
}
demo.h
int testFn();
demo.c
int testFn(){
return 0;
}
binding.gyp
{
"targets": [
{
"target_name": "addon","sources": [
"index.cpp"
],"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")"
],"dependencies": [
"<!(node -p \"require('node-addon-api').gyp\")"
]
}
]
}
构建错误信息
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 code: 1
gyp ERR! stack at ChildProcess.onExit (D:\node-v9.3.0-win-x64\node_modules\npm\node_modules\node-gyp\lib\build.js:258:23)
gyp ERR! stack at ChildProcess.emit (events.js:159:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "D:\\node-v9.3.0-win-x64\\node.exe" "D:\\node-v9.3.0-win-x64\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\createVideo
gyp ERR! node -v v9.3.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
有人知道我在调用上述代码时可能做错了什么吗? 谢谢。
ps: 我试图编辑binding.gyp文件(添加库项)
{
"targets": [
{
"target_name": "addon","sources": [
"hello.cpp"
],"libraries": [
"D:/lib/ffmpeg-4.2.1-win64-dev/lib/**"
],"dependencies": [
"<!(node -p \"require('node-addon-api').gyp\")"
]
}
],}
node-gyp构建正常,但无法正常运行,运行.js文件以要求本机模块异常错误:找不到指定的模块。