OpenCV安装,未解析的外部符号

时间:2012-11-23 22:18:16

标签: c++ opencv linker unresolved-external

  

可能重复:
  OpenCV: link error, can’t resolve external symbol _cvResize and _cvCvtColor
  What is an undefined reference/unresolved external symbol error and how do I fix it?

我已经尝试了他们网站上提供的所有教程,以及stackoverflow上的解决方案,但我仍然无法找到解决方案。

我已经做过的事情:

1-添加了包含标题的文件夹。

2-将lib文件夹添加到其他lib目录

3-将opencv_core243d.lib和opencv_highgui243d.lib添加到其他依赖项中。

代码我正在尝试编译:

#include <stdio.h>
#include <cv.h>
#include <highgui.h>


int main(int argc, char* argv[])
{
if (argc < 2)
{
    printf("Usage: ./opencv_hello <file.png>\n");
    return -1;
}

    IplImage* img = cvLoadImage(argv[1], CV_LOAD_IMAGE_UNCHANGED);
if (!img)
{
    return -1;
}
cvNamedWindow("display", CV_WINDOW_AUTOSIZE);
    cvShowImage("display", img );

    cvWaitKey(0);        

    return 0;
}

链接器提供有关未解析符号的错误,例如cvLoadImage,cvWaitKey等。 我唯一能想到的就是libs,但我已经把它们包括在内了。

1 个答案:

答案 0 :(得分:1)

据我了解,您正在使用OpenCV 2.4

在这种情况下,我想建议使用C ++接口。

#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

int main(int argc, char* argv[])
{

if (argc < 2)
{
    printf("Usage: ./opencv_hello <file.png>\n");
    return -1;
}

cv::Mat img = imread(argv[1]);
if (img.empty())
{
   return -1;
}

imshow("display", img);

waitKey(0); <---- cvWaitKey() is a C interface functio, waitKey() - C++

return 0;
}
相关问题