c++ - 无法在ubuntu中编译opencv程序

标签 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 吗?

最佳答案

在我看来,您忘记了指定一个模块

`pkg-config --libs MODULENAMEGOESHERE`

关于c++ - 无法在ubuntu中编译opencv程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19295055/

相关文章:

linux - 语法错误 : redirection unexpected netcat busybox

c++ - 对头文件和实现文件之间的关系感到困惑

c++ - 如何在 Visual C++ 中将浮点文字处理为 double 或 float ?

android - Android Lollipop 上的 va_start/va_end + vsnprintf 问题

algorithm - 收集数据来识别手绘几何图形的最佳算法和最佳方法是什么?

c++ - 在 OpenCV 中存储图像和指针

arrays - 使用python考虑每条线的交点对线进行分组

c++ - 如何迭代 IO Kit 的键?

php - 用于列出附加驱动器、已用空间和可用空间的 HTML/PHP

c++ - 内存仍可访问的错误已修复,但为什么呢?