0

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");
}   
Jos
  • 468
  • 1
  • 7
  • 20

4 Answers4

4

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.

Jos
  • 468
  • 1
  • 7
  • 20
1

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.

Jacob
  • 34,255
  • 14
  • 110
  • 165
  • sorry still not working. But I use c++. I was just checking if I have set up VS correctly for OpenCv. – Jos Aug 19 '13 at 13:16
  • Are you getting the same error? Can you read the `highgui_c` header file? – Jacob Aug 19 '13 at 13:30
  • Also, how did you link those libraries? Are you sure that the right directories and library names are specified in the project settings? – Jacob Aug 19 '13 at 13:37
  • in Properties->Linker I added library directories. This is the path i used D:\opencv\build\x64\vc10\lib then added individual libraries for both debug and release modes. In include directories, I added the path D:\opencv\build\include\opencv and D:\opencv\build\include . Hope I am right with the path. – Jos Aug 19 '13 at 13:50
  • Does `D:\opencv\build\include` contain the `opencv2\highgui\highgui_c.h` file? Did you add individual libraries in `Linker->Input->Additional Dependencies`? – Jacob Aug 19 '13 at 13:54
  • 1
    ok i got it. problem was with platform. It was in Win32. so i changed it to x64 and copied settings from Win32. finally working now. thanks for the help dude. – Jos Aug 19 '13 at 14:24
0

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.

virusrocks
  • 861
  • 1
  • 5
  • 19
  • yes i have done that. i added the ones that end in 'd' to debug libraries and the others to release libraries – Jos Aug 19 '13 at 12:30
  • If I am not wrong cvLoadImage and cvNamedWindow are not members from "highgui.h". I don't remember the exact headers they belong to. I have to look at the code back home. – virusrocks Aug 19 '13 at 12:34
0

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

Andrey Smorodov
  • 10,649
  • 2
  • 35
  • 42