我正在开发一个项目,该项目使用立体声相机的深度相机ZED来检索障碍物的距离。它的SDK是用C ++编写的,它需要CUDA 6.5。但是,我必须将此程序与项目的另一部分集成,该部分是用nodejs编写的。所以我决定将ZED代码编译为节点模块。我经历过node addon tutorial。现在我编写了界面,但是在尝试使用命令“node-gyp configure build”构建项目后出现了以下错误。 似乎'zed'模块没有构建。我不知道这个错误到底是什么,到目前为止我没有搜索过任何内容。有人可以给我一些指示吗?谢谢。
gyp info it worked if it ends with ok
gyp info using node-gyp@2.0.2
gyp info using node@0.12.7 | linux | x64
gyp info spawn python2
gyp info spawn args [ '/usr/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 '/Path/to/My/Project/DepthViewer/node_zed_module/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/usr/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/home/joe/.node-gyp/0.12.7/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/home/joe/.node-gyp/0.12.7',
gyp info spawn args '-Dnode_gyp_dir=/usr/lib/node_modules/node-gyp',
gyp info spawn args '-Dmodule_root_dir=/Path/to/My/Project/DepthViewer/node_zed_module',
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' ]
make: Entering directory `/Path/to/My/Project/DepthViewer/node_zed_module/build'
CXX(target) Release/obj.target/zed/../src/main.o
/bin/sh: 1: -DNODE_GYP_MODULE_NAME=zed: not found
make: [Release/obj.target/zed/../src/main.o] Error 127 (ignored)
SOLINK_MODULE(target) Release/obj.target/zed.node
/bin/sh: 1: -shared: not found
make: [Release/obj.target/zed.node] Error 127 (ignored)
COPY Release/zed.node
cp: cannot stat ‘Release/obj.target/zed.node’: No such file or directory
make: *** [Release/zed.node] Error 1
make: Leaving directory `/Path/to/My/Project/DepthViewer/node_zed_module/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/lib/node_modules/node-gyp/lib/build.js:269:23)
gyp ERR! stack at ChildProcess.emit (events.js:110:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:1074:12)
gyp ERR! System Linux 3.13.0-58-generic
gyp ERR! command "node" "/usr/bin/node-gyp" "configure" "build"
gyp ERR! cwd /Path/to/My/Project/DepthViewer/node_zed_module
gyp ERR! node -v v0.12.7
gyp ERR! node-gyp -v v2.0.2
gyp ERR! not ok
这是我的binding.gyp:
{
"targets": [
{
"target_name": "zed",
"sources": [
"../src/main.cpp",
],
"include_dirs": [
"/usr/local/zed/include/",
"/usr/local/cuda-6.5/include/",
"../include/"
],
}
]
}
这是我的package.json:
{
"name": "zed_depth_viewer",
"version": "0.0.0",
"description": "Measure depth with zed sdk",
"main": "zed_depth.js",
"private": true,
"gypfile": true,
"dependencies": {
"bindings": "~1.2.1"
}
}
以下基本上是我与节点的接口:(刚刚开始测试,'initProgram'作为项目的'main'工作)
void node_main_handle(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, initProgram);
Local<Function> fn = tpl->GetFunction();
// omit this to make it anonymous
fn->SetName(String::NewFromUtf8(isolate, "initProgram"));
args.GetReturnValue().Set(fn);
}
void Init(Handle<Object> exports, Handle<Object> module)
{
NODE_SET_METHOD(module, "exports", node_main_handle);
}
NODE_MODULE(zed, Init)
使用此模块的示例应为:
var zed = require('bindings')('zed'); //zed.node will be in './build/Release/'
var func = zed();
func();
不确定这是否有效,尚未测试过。我是nodejs的新手。
答案 0 :(得分:1)
从/bin/sh: 1: -DNODE_GYP_MODULE_NAME=zed: not found
行看来无法找到编译器(它应该类似于/usr/bin/g++
而不是/bin/sh
)。如果你想将自定义标志传递给gyp,或者你想要一个特定的编译器,你的gyp文件应该是这样的:
{
'make_global_settings': [
['CXX','/usr/bin/clang++-3.5'],
['LINK','/usr/bin/clang++-3.5'],
],
"targets": [
{
"target_name": "zed",
"sources": [
"../src/main.cpp",
],
"include_dirs": [
"/usr/local/zed/include/",
"/usr/local/cuda-6.5/include/",
"../include/"
],
"link_settings": {
"libraries": [ // For compiler
"-requiredlibs",
],
"ldflags": [ // For linker
"-L</path/to/libs",
"-Wl,-rpath,path/to/libs",
]
},
"cflags": [
"-std=c++11"
],
}
]
}
上面的gyp文件使用clang
(而不是g++
)进行编译和链接,并为创建的共享库设置正确的rpath
,因此您不需要导出每次要使用绑定时都要使用库路径!
有关详细信息,this article可能有用!