gpt4 book ai didi

c++ - 运行 OpenNI 2 类时出错(gcc 4.7.2/ubuntu 12.10)

转载 作者:太空宇宙 更新时间:2023-11-04 12:00:22 24 4
gpt4 key购买 nike

我正在尝试编译运行下面给出的一个非常基本的程序 (test.cpp),它调用 OpenNI 类。您可以在此处查看它们所在的文件和目录。抱歉,某些字符在浏览器的编码中出现了一些问题。我正在使用 linux 命令:tree,如果您知道更好的命令请告诉我,我会更新它。

File Structure

我正在按照指南 here ,参见“GCC/GNU Make”。

#include < stdio.h > 
#include < OpenNI.h >

using namespace openni;

int
main ( void )
{
Status rc = OpenNI::initialize();

if (rc != STATUS_OK)
{
printf("\nInitialize failed\n%s\n", OpenNI::getExtendedError());
return 1;
}

printf("Hello, world!\n");
return 0;
}

这是我在命令行中运行的编译程序(gcc 4.7.2):

gcc test.cpp -I../OpenNI-2.0.0/Include -L/home/evan/Code/OpenNi/Init -l OpenNI2 -o test 

这工作正常,但是当我运行 ./test 时,出现以下错误:

Initialize failed 
DeviceDriver: library handle is invalid for file libOniFile.so
Couldn't understand file 'libOniFile.so' as a device driver
DeviceDriver: library handle is invalid for file libPS1080.so
Couldn't understand file 'libPS1080.so' as a device driver
Found no valid drivers in './OpenNI2/Drivers'

谢谢,我们将不胜感激。

最佳答案

导游的指示说,

It is highly suggested to also add the "-Wl,-rpath ./" to your linkage command. Otherwise, the runtime linker will not find the libOpenNI.so file when you run your application. (default Linux behavior is to look for shared objects only in /lib and /usr/lib).

看来您确实遇到了这个问题——找不到某些库。尝试将正确的 rpath(在你的情况下似乎是/home/evan/Code/OpenNi/Init/OpenNI2/Drivers)添加到你的编译字符串。

关于c++ - 运行 OpenNI 2 类时出错(gcc 4.7.2/ubuntu 12.10),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14383759/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com