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 intoonijs/
(Redist
has a directoryOpenNI2
so now I haveonijs/OpenNI2
with some drivers in it). - Copied the
Includes
folder intoonijs/src/
- Copied the basic "Hello World" into
onijs/src/main.cpp
- Placed my
binding.gyp
file inonijs/
- In a terminal I did
cd /pathTo/onijs/
and rannode-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.
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