如何编写binding.gyp以使用OpenNI构建一个Node.js插件? [英] How should binding.gyp be written to build a Node.js addon with OpenNI?
问题描述
我试图构建一个使用OpenNI的Node.js插件。我没有使用Node-gyp之前,所以我试图设置binding.gyp文件,以便它包括OpenNI库作为构建的一部分。我实际编译的代码只是 Hello World示例。
我使用的binding.gyp文件基于 NUIMotion 在Github上,这是做类似的东西。这是我的:
{
pre>
targets:[
{
target_name: onijs,
sources:[
src / main.cpp],
include_dirs:[./src/Include],
libraries:[-lOpenNI2,-Wl,-rpath ./]
}
]
}
以下是我在OSX中所做的工作:
- 创建了一个名为
的节点项目文件夹onijs /
- 下载并提取了OpenNI
- 的
Redist
目录插入onijs /
(Redist
目录OpenNI2
所以现在我有onijs / OpenNI2
有一些驱动程序)。 - 将
包含
文件夹复制到onijs / src /
- 基本的Hello World变成
onijs / src / main.cpp
- 放置我的
binding.gyp
on $ / code> - 在
/
并运行
node-gyp configure
,工作正常 - 然后我跑了
node-gyp build
,并且barfed。
错误是ld:library找不到-lOpenNI2。
我在这里采取了错误的做法吗?我没有在库声明中的 -l </ code>和
-Wl,-rpath ./
,但它仍然没有't build。
几个快速选项
如果OpenNI2是单个动态库,您可以直接添加到您的库列表
/ path / libOpenNI2_file
如果OpenNI2是软件包的一部分,您可以使用pkg-config图书馆
pkg-config --libs OpenNI2
有关此特定库的更多文档,请访问 OpenNI < a>
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
这篇关于如何编写binding.gyp以使用OpenNI构建一个Node.js插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!