OpenCv unresolved external symbol error in Visual Studio

冷暖自知 提交于 2020-01-17 04:11:29

问题


I have linked to the libraries I want to use and added the header files to my project. And the code doesn't show any errors in red squiggle but when I try to run it, it gives me the following error:

Error   1   error LNK2001: unresolved external symbol _cvDestroyWindow  C:\Users\Jos\documents\visual studio 2010\Projects\ocv\ocv\opcv.obj ocv
Error   2   error LNK2001: unresolved external symbol _cvWaitKey    C:\Users\Jos\documents\visual studio 2010\Projects\ocv\ocv\opcv.obj ocv
Error   3   error LNK2001: unresolved external symbol _cvNamedWindow    C:\Users\Jos\documents\visual studio 2010\Projects\ocv\ocv\opcv.obj ocv
Error   4   error LNK2001: unresolved external symbol _cvLoadImage  C:\Users\Jos\documents\visual studio 2010\Projects\ocv\ocv\opcv.obj ocv
Error   5   error LNK2001: unresolved external symbol _cvShowImage  C:\Users\Jos\documents\visual studio 2010\Projects\ocv\ocv\opcv.obj ocv
Error   6   error LNK2001: unresolved external symbol _cvReleaseImage   C:\Users\Jos\documents\visual studio 2010\Projects\ocv\ocv\opcv.obj ocv
Error   7   error LNK1120: 6 unresolved externals   C:\Users\Jos\documents\visual studio 2010\Projects\ocv\Release\ocv.exe  ocv

And Here is the code:

#include "highgui.h"

int main(int argc, char **argv) {
    IplImage* img = cvLoadImage(argv[1],CV_LOAD_IMAGE_UNCHANGED);
    cvNamedWindow("Example1",CV_WINDOW_AUTOSIZE);
    cvShowImage("Example1",img);
    cvWaitKey(0);
    cvReleaseImage(&img);
    cvDestroyWindow("Example1");
}   

回答1:


Ok it finally works. My PC is a 64-bit system. But the project was running on Win32 platform. So I changed it to x64 and copied settings from Win32.




回答2:


Since you are using the latest version of OpenCV, the C modules are accessible through

#include <opencv2\highgui\highgui_c.h>

or

#include "opencv2\highgui\highgui_c.h"

assuming that the opencv2 folder is in your list of Include directories.

However, I would highly recommend that you start using the Mat object (instead of IplImage) and other C++ equivalents in OpenCV. It will make your life much easier at no significant cost to performance.




回答3:


Please use Debug libraries if you are running in debug mode else Release once. You can find these two version in the OPENCV folder hierarchy.




回答4:


It seems that you have not attached highgui.lib, and may be legacy.lib to project. (I have omitted version number in filenames).



来源:https://stackoverflow.com/questions/18313769/opencv-unresolved-external-symbol-error-in-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!