Node-gyp构建失败。无法在包含目录的子目录中找到库头文件

时间:2019-04-03 10:46:24

标签: c++ node.js node-gyp

我想在Node.js应用程序中使用DronecodeSDK(C ++)库。我目前无法构建包含DronecodeSDK标头的node-addon。 node-gyp找不到子子目录中的标头。

包括

#include <dronecode_sdk/dronecode_sdk.h>很好,但是没有#include <dronecode_sdk/plugins/action/action.h>

如果我将action.h文件移动到dronecode_sdk/action.h,那么包含就可以了。只有在将其移动到插件的子目录中时,才可以找到它。

我的binding.gyp文件:

{
  "targets": [
    {
      "include_dirs" : [
            "<!(node -e \"require('nan')\")",
            "../lib/DronecodeSDK/install/include"
        ],
     "libraries": [ "../lib/DronecodeSDK/install/lib/libdronecode_sdk.a" ],
      "target_name": "DronecoreSDK",
      "sources": [ "DronecoreSDKBridge.cc" ]
    }
  ]
}

'DronecodeSDKBridge.cc'中有两个include语句:

#include <dronecode_sdk/dronecode_sdk.h>
#include <dronecode_sdk/plugins/action/action.h>

我收到以下错误消息:

gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@10.15.0 | darwin | x64
gyp info spawn /usr/local/bin/python2
gyp info spawn args [ '/usr/local/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/aokholm/src/kitex/_3_GroundStation/electron-GC/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/aokholm/.node-gyp/10.15.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/aokholm/.node-gyp/10.15.0',
gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/aokholm/.node-gyp/10.15.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/aokholm/src/kitex/_3_GroundStation/electron-GC',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CXX(target) Release/obj.target/DronecoreSDK/DronecoreSDKBridge.o
../DronecoreSDKBridge.cc:10:10: fatal error: 'dronecode_sdk/plugins/action/action.h' file not found
#include <dronecode_sdk/plugins/action/action.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [Release/obj.target/DronecoreSDK/DronecoreSDKBridge.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Darwin 18.2.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/bin/node-gyp" "rebuild"
gyp ERR! cwd /Users/aokholm/src/kitex/_3_GroundStation/electron-GC
gyp ERR! node -v v10.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

是子子目录不起作用,还是其他地方出现错误?我检查了所有标头文件的文件权限是否可读。

1 个答案:

答案 0 :(得分:0)

Node-gyp路径非常神秘。

库路径../lib/DronecodeSDK/install/lib/libdronecode_sdk.a是正确的。但是,包含路径../lib/DronecodeSDK/install/include不正确。

无论如何,node-gyp都能找到dronecode_sdk.h头的原因是,它默认情况下在项目的两个最顶层目录中搜索头。

更改包含lib/DronecodeSDK/install/include的包含路径可以解决此问题。