本文介紹了OpenCV 2.3 編譯問(wèn)題 - 未定義參考 - Ubuntu 11.10的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
系統(tǒng)信息:Ubuntu 11.10(64 位)和 OpenCV 2.3(今天安裝)
System Info: Ubuntu 11.10 (64 bits) with OpenCV 2.3 (installed today)
我正在嘗試在 OpenCV 2.3 中編譯一些非常簡(jiǎn)單的代碼,但出現(xiàn)了一個(gè)奇怪的錯(cuò)誤.
I'm trying to compile some very simple code in OpenCV 2.3 but I'm getting a weird error.
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(){
cv::Mat image=cv::imread("img.jpg");
cv::namedWindow("My Image");
cv::imshow("My Image",image);
cv::waitKey(0);
return 1;
}
但是,我收到了這些錯(cuò)誤消息...
however, I'm getting these error messages...
-SG41:~/Desktop$ g++ `pkg-config opencv --cflags --libs` -o test_1 test_1.cpp
/tmp/ccCvS1ys.o: In function `main':
test_1.cpp:(.text+0x44): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test_1.cpp:(.text+0x8e): undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test_1.cpp:(.text+0xbc): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
test_1.cpp:(.text+0xf0): undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
test_1.cpp:(.text+0x112): undefined reference to `cv::waitKey(int)'
/tmp/ccCvS1ys.o: In function `cv::Mat::~Mat()':
test_1.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/ccCvS1ys.o: In function `cv::Mat::release()':
test_1.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x47): undefined reference to `cv::Mat::deallocate()'
collect2: ld returned 1 exit status
推薦答案
我猜至少有一些庫(kù)在
pkg-config opencv --libs
是檔案庫(kù).將存檔庫(kù)放在需要它們的源之前是不正確的(在這種情況下為 test_1.cpp
):鏈接行上源和庫(kù)的順序 很重要.
are archive libraries. It is incorrect to put archive libraries before sources that need them (test_1.cpp
in this case): the order of sources and libraries on the link line matters.
試試
g++ -o test_1 test_1.cpp `pkg-config opencv --cflags --libs`
這篇關(guān)于OpenCV 2.3 編譯問(wèn)題 - 未定義參考 - Ubuntu 11.10的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!