Jos
Jos

Reputation: 468

OpenCv unresolved external symbol error in Visual Studio

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");
}   

Upvotes: 0

Views: 5416

Answers (4)

Jos
Jos

Reputation: 468

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.

Upvotes: 4

Andrey  Smorodov
Andrey Smorodov

Reputation: 10850

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

Upvotes: 0

Jacob
Jacob

Reputation: 34621

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.

Upvotes: 1

virusrocks
virusrocks

Reputation: 871

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.

Upvotes: 0

Related Questions