簡體   English   中英

使用 node-gyp 異常:LNK2001 未解析的外部符號

[英]use node-gyp exception : LNK2001 unresolved external symbol

使用 node-gyp 構建原生模塊(嘗試將 ffmpeg 用於我的 cpp 文件),它拋出異常:錯誤 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 文件以要求本機模塊異常錯誤:找不到指定的模塊。

您可能沒有包含庫文件

例如,你有一個帶有一些函數的頭文件

但函數從未聲明,因為 CPP 文件或庫不存在

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM