How should binding.gyp be written to build a Node.js addon with OpenNI?

烂漫一生 提交于 2019-12-07 19:25:03

问题


I'm trying to build a Node.js addon that makes use of OpenNI. I haven't used Node-gyp before so I'm trying to set up the binding.gyp file so that it includes the OpenNI library as part of the build. The code I'm actually compiling is just the Hello World example.

The binding.gyp file I'm using is based on the one from NUIMotion on Github, which is doing something similar. Here's mine:

{
    "targets": [
    {
        "target_name": "onijs",
        "sources": [
            "src/main.cpp" ],
        "include_dirs": [ "./src/Include" ],

        "libraries": [ "-lOpenNI2", "-Wl,-rpath ./" ]
    }
  ]
}

Here's what I've done (working in OSX):

  • Created a node project folder called onijs/
  • Downloaded and extracted OpenNI
  • Copied the contents of the Redist directory into onijs/ (Redist has a directory OpenNI2 so now I have onijs/OpenNI2 with some drivers in it).
  • Copied the Includes folder into onijs/src/
  • Copied the basic "Hello World" into onijs/src/main.cpp
  • Placed my binding.gyp file in onijs/
  • In a terminal I did cd /pathTo/onijs/ and ran node-gyp configure, which worked fine
  • Then I ran node-gyp build, and it barfed.

The error is "ld: library not found for -lOpenNI2."

Am I taking the wrong approach here? I have tried it without the -l and -Wl, -rpath ./ in the libraries declaration but it still doesn't build.


回答1:


A couple of quick options

If OpenNI2 is a single dynamic library you can add directly to your libraries list

/path/to/libOpenNI2_file

If OpenNI2 is part of a package, you may be able to use pkg-config to get the libraries with

pkg-config --libs OpenNI2

There's more documentation about this specific library here at OpenNI



来源:https://stackoverflow.com/questions/16737863/how-should-binding-gyp-be-written-to-build-a-node-js-addon-with-openni

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!