无法在ubuntu中编译opencv程序

时间:2013-10-10 11:52:58

标签: c++ linux opencv 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?

1 个答案:

答案 0 :(得分:1)

在我看来,你忘了在

中指定一个模块
`pkg-config --libs MODULENAMEGOESHERE`