2015-04-04 119 views
0

第一次在這裏提問時,如果我不完全一致,請耐心等待。在Ubuntu Linux上使用Kinect進行編程

我一直在試圖學習如何使用OpenNI,libfreenect和SensorKinect庫來爲kinect創建一些代碼。然而,我遇到的問題是,我似乎無法正確地獲取kinect設置,以便我可以實際測試代碼並瞭解每件事情如何工作。這個問題最成問題的是當我嘗試編譯時,我收到大量未定義的引用錯誤,並且編譯器退出。

/tmp/ccnXAyOZ.o: In function `main': 
KinectDraw.cpp:(.text+0x9a): undefined reference to `xnEnumerationErrorsAllocate' 
KinectDraw.cpp:(.text+0xb6): undefined reference to `xnGetStatusString' 
KinectDraw.cpp:(.text+0xfa): undefined reference to `xnInitFromXmlFileEx' 
KinectDraw.cpp:(.text+0x12a): undefined reference to `xnEnumerationErrorsToString' 
KinectDraw.cpp:(.text+0x148): undefined reference to `xnEnumerationErrorsFree' 
KinectDraw.cpp:(.text+0x169): undefined reference to `xnGetStatusString' 
KinectDraw.cpp:(.text+0x18a): undefined reference to `xnEnumerationErrorsFree' 
KinectDraw.cpp:(.text+0x1a4): undefined reference to `xnEnumerationErrorsFree' 
KinectDraw.cpp:(.text+0x1bf): undefined reference to `xnFindExistingRefNodeByType' 
KinectDraw.cpp:(.text+0x1db): undefined reference to `xnGetStatusString' 
KinectDraw.cpp:(.text+0x202): undefined reference to `xnAllocateDepthMetaData' 
KinectDraw.cpp:(.text+0x227): undefined reference to `xnWaitOneUpdateAll' 
KinectDraw.cpp:(.text+0x243): undefined reference to `xnGetStatusString' 
KinectDraw.cpp:(.text+0x273): undefined reference to `xnGetDepthMetaData' 
KinectDraw.cpp:(.text+0x2fe): undefined reference to `xnOSWasKeyboardHit' 
KinectDraw.cpp:(.text+0x31a): undefined reference to `xnFreeDepthMetaData' 
KinectDraw.cpp:(.text+0x329): undefined reference to `xnProductionNodeRelease' 
KinectDraw.cpp:(.text+0x338): undefined reference to `xnProductionNodeRelease' 
KinectDraw.cpp:(.text+0x347): undefined reference to `xnContextRelease' 
/tmp/ccnXAyOZ.o: In function `xn::NodeWrapper::SetHandle(XnInternalNodeData*)': 
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0x39): undefined reference to `xnGetRefContextFromNodeHandle' 
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0x54): undefined reference to `xnContextUnregisterFromShutdown' 
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0x60): undefined reference to `xnContextRelease' 
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0x6f): undefined reference to `xnProductionNodeRelease' 
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0x82): undefined reference to `xnProductionNodeAddRef' 
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0x91): undefined reference to `xnGetRefContextFromNodeHandle' 
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0xb2): undefined reference to `xnContextRegisterForShutdown' 
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0xc1): undefined reference to `xnContextRelease' 
collect2: error: ld returned 1 exit status 

正在接收錯誤的命令是g++ KinectDraw.cpp -I /usr/include/ni -I ~/KinectLibs/OpenNI/Include。我用https://www.kdab.com/setting-up-kinect-for-programming-in-linux-part-1/來設置kinect。如果有人對我的問題有任何洞見,甚至只是一個開始閱讀的好地方,我會非常感激。感謝您的時間和協助!

更新:感謝lxrec的評論,我很確定她/他和我最初的假設是正確的,因爲我沒有正確鏈接庫。我還沒有找到任何有關Linux編譯代碼的文檔,其中包括用於編譯的目錄,所以如果有人對此有所瞭解,我會很感激。

更新:所以我仍然沒有解決這個問題(我不知道如何編譯代碼),但是認爲我的OpenNI或libfreenect安裝不好,我已經樹脂安裝了它們。但是,這並沒有解決我的問題。感謝任何能夠提供見解的人!

更新:下面是我遇到問題編譯的代碼。我還沒有嘗試添加任何東西到它尚未...

#include <XnCppWrapper.h> 
#include <XnStatusCodes.h> 
#include <XnOS.h> 
#include <math.h> 
#include <XnOpenNI.h> 
#include <iostream> 

using namespace xn; 
using namespace std; 

int main() 
{ 
    cout<<"This is a test\n"; 
    return 0; 
} 
+1

如果沒有代碼片段,我們無能爲力。 – 2015-04-04 22:46:34

+0

「未定義的引用」聽起來像標準鏈接器錯誤,意思是「你編譯時針對X的頭文件,但沒有鏈接到X的目標文件,所以我不能鏈接你的可執行文件。」由於你的命令行有-I標誌,但沒有-L標誌,它可能很簡單。 – Ixrec 2015-04-05 19:09:39

+0

這就是我正在考慮的lxrec,我只是一直無法找到正確的目錄,而且我搜索的每個地方都是一個deadend(我發現甚至列出了Windows路徑的OpenNI官方文檔)。如果我錯了,我更模棱兩可地說這個問題。布賴恩,當我今晚可以上傳代碼示例時,但目前唯一的物質是#include。我在那裏有更多的代碼,但在測試過程中評論了大部分代碼,以查看出了什麼問題。再次感謝你們! – 2015-04-08 15:44:15

回答

1

OpenNI源代碼應該包括在其lib目錄($SOURCE_DIR/Platform/Linux/Redist/OpenNI-Bin-Dev-Linux-x64-v1.5.7.10-$YOUR_VERSION/lib)的庫文件(.so文件)。所有這些文件(對我有5個文件:libnimCodecs.so,libnimMockNodes.so,libnimRecorder.solibOpenNI.jni.solibOpenNI.so)運行install.sh(請遵循OpenNI編譯/安裝說明)

後正在複製到/ usr/lib目錄你的示例代碼需要一個-lOpenNI arg來完成編譯過程。所以你應該像這樣編譯你的代碼:g++ your_code.cpp -I/usr/include/ni -lOpenNI

這可能已經是一個老問題了,希望你的問題已經解決了,下次這個答案可以幫助別人。

相關問題