[英]can not compile opencv programs in ubuntu
我寫了一個像這樣的簡單程序
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, const char* argv[])
{
Mat input = imread(argv[1], 0); //Load as grayscale
//~ FAST detector;
//~ vector<KeyPoint> keypoints;
//~ FAST(input, keypoints, 0.2);
// Add results to image and save.
//~ Mat output;
//~ drawKeypoints(input, keypoints, output);
namedWindow ("Image", CV_WINDOW_FREERATIO);
imshow("Image", input);
//~ imwrite(argv[2], output);
return 0;
}
然后像這樣編譯程序:
g++ `pkg-config --libs opencv` main.cpp
這是g++
輸出:
/tmp/ccK1Sbrw.o: In function `main':
main.cpp:(.text+0x66): undefined reference to `cv::imread(std::string const&, int)'
main.cpp:(.text+0xc2): undefined reference to `cv::namedWindow(std::string const&, int)'
main.cpp:(.text+0xf6): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
main.cpp:(.text+0x139): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
/tmp/ccK1Sbrw.o: In function `cv::Mat::~Mat()':
main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/ccK1Sbrw.o: In function `cv::Mat::release()':
main.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47): undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status
我已經安裝了庫,可以在它們的文件夾中看到* .so和* .hpp文件,並且ld
找到了它們,但是它抱怨什么呢? .so文件中沒有任何內容?
另外,我沒有安裝非自由模塊(我使用apt-get
安裝opencv),如何獲得它們? 我需要該模塊內部的SIFT。 我必須自己編譯opencv嗎?
在我看來,您忘記了在其中指定模塊
`pkg-config --libs MODULENAMEGOESHERE`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.