[英]use node-gyp exception : LNK2001 unresolved external symbol
use node-gyp build native module(try to use ffmpeg to my cpp files), it throws an exception: error LNK2001 unresolved external symbol使用 node-gyp 构建原生模块(尝试将 ffmpeg 用于我的 cpp 文件),它抛出异常:错误 LNK2001 未解析的外部符号
example code:示例代码:
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\")"
]
}
]
}
build error info构建错误信息
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
Does anyone know what I might be doing wrong in my invocation of the above?有谁知道我在调用上述内容时可能做错了什么? Thank you.谢谢你。
ps: I tried to edit binding.gyp file (add libraries item) 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 build is ok , but can't work , run .js file to require native module exception Error: The specified module could not be found. node-gyp 构建没问题,但不能工作,运行 .js 文件以要求本机模块异常错误:找不到指定的模块。
you may not have included the library files您可能没有包含库文件
for example, u have a header file with some functions例如,你有一个带有一些函数的头文件
but the functions never declared because the CPP file or the library is not present但函数从未声明,因为 CPP 文件或库不存在
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.