16

This is my code in Visual Studio C++

#include "stdafx.h"
#include<opencv\cv.h>
#include<opencv\highgui.h>

using namespace cv;

int main(int argc, char** argv[]) {
  IplImage* img = cvLoadImage("logo.jpg");
  cvNamedWindow("Test", CV_WINDOW_AUTOSIZE);
  cvShowImage("Test", img);
  cvWaitKey(0);
  cvReleaseImage(&img);
  cvDestroyWindow("Test");
  return 0;
}

I am using OpenCV 2.4.6 and Visual Studio 2010. This is the error:

openCV_testing.obj : error LNK2019: unresolved external symbol _cvDestroyWindow
referenced in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvReleaseImage     
referenced in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvWaitKey referenced in  
function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvShowImage referenced   
in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvNamedWindow    
referenced in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvLoadImage referenced 
in function _main

Please help.

dda
  • 6,030
  • 2
  • 25
  • 34
sandy
  • 509
  • 1
  • 6
  • 23

5 Answers5

21

'unresolved external symbol' means that you're not linking with required library. Go to Properties -> Linker -> Additional Library dependencies and add path to OpenCV libs.

Biswajit Roy
  • 508
  • 2
  • 7
  • 19
ladan
  • 423
  • 4
  • 10
11

First check How to build applications with OpenCV inside the Microsoft Visual Studio

If you still suffer from the same problem, you could be under one of the below cases.

  1. Your active solution platform is x86 but you are trying to link x64 OpenCV libraries.
  2. Your active solution platform is X64 but you are trying to link x86 OpenCV libraries.

If you are under one of these cases, check Compiling a 64-bit Application in Microsoft Visual Studio Express 2010

zjkgoo
  • 111
  • 1
  • 2
10

Add these into your code:

#pragma comment (lib, "opencv_core248d.lib")
#pragma comment (lib, "opencv_highgui248d.lib")
#pragma comment (lib, "opencv_imgproc248d.lib")
#pragma comment (lib, "opencv_video248d.lib")
#pragma comment (lib, "opencv_features2d248d.lib")

It worked for me.

Ande
  • 101
  • 1
  • 3
  • That did it... But why? EDIT: This help explains it: http://stackoverflow.com/questions/3484434/what-does-pragma-comment-mean – shim Jan 13 '16 at 21:47
0

i searched a lot for the same problem this was the best solution i had found and it worked for me.

Open Configuration Properties > C/C++ > General, and edit the field Additional Include Directories to add these 3 paths (for the headers):

C:\OpenCV2.3\build\include\opencv

C:\OpenCV2.3\build\include\opencv2

C:\OpenCV2.3\build\include

yamen
  • 19
  • 2
0

I know this is not about the OpenCV library, but I already had a problem importing Tiny-Process library. My .lib file was linked correctly in Configuration Properties -> Linker -> Additional Library dependencies and the Additionnal Include Directories were correctly added but the the functions definition (s) were still not found and I was getting the LNK2019 error.

To fix the issue, I had to go in the library project properties, change the Character Set property in Configuration Properties -> Advanced Character Set and change the value Use Multi-Byte Character Set to Use Unicode Character Set.

After recompiling the library and using the new .lib file, it was working.

Phil
  • 19
  • 3