如何编写binding.gyp以使用OpenNI构建一个Node.js插件? [英] How should binding.gyp be written to build a Node.js addon with OpenNI?

查看:1113
本文介绍了如何编写binding.gyp以使用OpenNI构建一个Node.js插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图构建一个使用OpenNI的Node.js插件。我没有使用Node-gyp之前,所以我试图设置binding.gyp文件,以便它包括OpenNI库作为构建的一部分。我实际编译的代码只是 Hello World示例



我使用的binding.gyp文件基于 NUIMotion 在Github上,这是做类似的东西。这是我的:

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

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

以下是我在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 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.

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆