سؤال

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");
}   
هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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.

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.

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top