简体   繁体   中英

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

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)

{
  "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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM