使用 node-gyp 异常:LNK2001 未解析的外部符号

use node-gyp exception : LNK2001 unresolved external symbol

使用node-gyp构建原生模块(尝试对我的cpp文件使用ffmpeg),抛出异常:error LNK2001 unresolved external symbol

示例代码:

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 Studio17\BuildTools\MSBuild.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 文件需要本机模块异常错误:找不到指定的模块。

您可能没有包含库文件

例如,你有一个包含一些函数的头文件

但函数从未声明,因为 CPP 文件或库不存在