2016-04-21 135 views
2

我是cpp的新手,想要實現粒子濾鏡,我嘗試在這裏運行代碼https://github.com/NewProggie/Particle-Filter,這是一個結構化且易於理解的項目。但是,當我嘗試編譯和鏈接:體系結構x86_64的未定義符號:鏈接錯誤?

g++ $(pkg-config --cflags --libs opencv) -I/usr/local/Cellar/opencv3/3.1.0_1/include -I /usr/local/Cellar/gsl/1.16/include -stdlib=libc++ main.cpp -o main 

我有以下鏈接的問題:

Undefined symbols for architecture x86_64: 
"colorFeatures::colorFeatures()", referenced from: 
    _main in main-2b4c23.o 
"colorFeatures::~colorFeatures()", referenced from: 
    _main in main-2b4c23.o 
"adaboostDetect::detectObject(_IplImage*, CvRect**)", referenced from: 
    _main in main-2b4c23.o 
"adaboostDetect::adaboostDetect()", referenced from: 
    _main in main-2b4c23.o 
"tracker::addObjects(_IplImage*, CvRect*, int)", referenced from: 
    _main in main-2b4c23.o 
"tracker::initTracker(_IplImage*, CvRect*, int, int)", referenced from: 
    _main in main-2b4c23.o 
"tracker::showResults(_IplImage*)", referenced from: 
    _main in main-2b4c23.o 
"tracker::next(_IplImage*)", referenced from: 
    _main in main-2b4c23.o 
"tracker::tracker()", referenced from: 
    _main in main-2b4c23.o 
"tracker::~tracker()", referenced from: 
    _main in main-2b4c23.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

任何一種人有這個問題的想法?提前致謝

+0

由於項目提供了'CMakeLists.txt',使用'CMake'生成一個makefile會更簡單。 – drescherjm

+0

嘗試添加庫搜索路徑到opencv庫 g ++ $(pkg-config --cflags --libs opencv)-I/usr/local/Cellar/opencv3/3.1.0_1/include -I/usr/local/Cellar /gsl/1.16/include -L/usr/local/Cellar/opencv3/3.1.0_1/lib -stdlib = libC++ main.cpp -o main –

+0

@drescherjm:謝謝,但您能否詳細告訴我下一步該怎麼做?我可以使用cmake生成CMakeFiles文件夾,main.app,cmake_install.cmake,但如何處理這些東西?謝謝 – printemp

回答

1

已正確安裝gsl B)傳遞給g ++對gsl庫所在lib目錄的引用(可能類似於/ usr/lib或/ usr/local/lib,這些都應該是缺省值鏈接器要搜索的位置)以及頭文件的位置,並告訴鏈接器進行鏈接。

g++ -o <name of executable> -L/path/to/gsl/libs -I/path/to/headers -lgsl <name of source file> 

的-L告訴它在哪裏找到庫(.so Linux上的文件,在OS X名爲.dylib),-I告訴它在哪裏可以找到頭,-l(這是一個小寫L)告訴它鏈接到庫,它將被命名爲libgsl.so或libgsl.dylib。

首先嚐試添加-lgsl標誌,然後如果它找不到libgsl.so(或.dylib),則添加-L標誌。注意:/ path/to/gsl/libs和/ path/to/headers不是您應該直接放在那裏的內容,而是將它們替換爲系統上的實際路徑。

相關問題