C++ OpenCV:对 imread() 的未定义引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34497099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:23:19  来源:igfitidea点击:

OpenCV : undefined reference to imread()

c++eclipsewindowsopencvimread

提问by Shinchan

I have configured OpenCV 3.1.0 in Eclipse Mars. These are my configuration,

我已经在 Eclipse Mars 中配置了 OpenCV 3.1.0。这些是我的配置,

G++ includes: D:/opencv/build/install/include; GCC includes: D:/opencv/build/install/include

G++ 包括:D:/opencv/build/install/include;GCC 包括:D:/opencv/build/install/include

Linker libraries: libopencv_core310, libopencv_highgui310

链接器库:libopencv_core310、libopencv_highgui310

Linker libraries path: D:/opencv/build/lib (files in this directory are like libopencv_core310.dll.a)

链接库路径:D:/opencv/build/lib(该目录下的文件类似于libopencv_core310.dll.a)

I am getting an error like this,

我收到这样的错误,

imageRead.cpp:15: undefined reference to `cv::imread(cv::String const&, int)'

This is my imageRead.cpp file,

这是我的 imageRead.cpp 文件,

#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"

using namespace std;
using namespace cv;

int main(int argc, const char** argv) {
    Mat img = imread("D:/sample.jpg", CV_LOAD_IMAGE_UNCHANGED);
    if (img.empty()) {
        cout << "Error: Image cannot be loaded." << endl;
        system("pause");
        return -1;
    }
    namedWindow("Image Window", CV_WINDOW_AUTOSIZE);
    imshow("Image Window", img);
    if (waitKey() == 27) {
        return -1;
    }
    destroyWindow("Image Window");
    return 0;
}

Can anyone help with this error ?

任何人都可以帮助解决这个错误吗?

回答by Morris Franken

Since OpenCV3, the imread function resides in the imgcodecs module. Imread should work once you add the opencv_imgcodecslibrary to your project (note: imgcodecs, not imcodecs).

从 OpenCV3 开始, imread 函数驻留在 imgcodecs 模块中。一旦将opencv_imgcodecs库添加到项目中,Imread 应该可以工作(注意:imgcodecs,而不是 imcodecs)。

回答by Oscar Zhou1989

I recommend to link the following libraries:

我建议链接以下库:

opencv_core
opencv_highgui
opencv_imgproc
opencv_imgcodecs

And in the .cpp file, you can include like this

在 .cpp 文件中,您可以像这样包含

    #include <iostream>
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/imgproc/imgproc.hpp>

    using namespace std;
    using namespace cv;

Or

或者

    #include <iostream>
    #include <opencv2/opencv.hpp>

    using namespace std;
    using namespace cv;