Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LNK2019: unresolved external symbol error in Visual Studio C++

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.

like image 454
sandy Avatar asked Jul 21 '13 07:07

sandy


People also ask

What is error LNK2019?

LNK2019 can occur when a declaration exists in a header file, but no matching definition is implemented. For member functions or static data members, the implementation must include the class scope selector. For an example, see Missing Function Body or Variable.

How do I fix LNK1120 error?

The LNK1120 message comes last, and shows the unresolved symbol error count. You don't need to fix this error. This error goes away when you correct all of the LNK2001 and LNK2019 linker errors before it in the build output.

How do I fix unresolved external symbol LNK2001?

To fix this issue, add the /NOENTRY option to the link command. This error can occur if you use incorrect /SUBSYSTEM or /ENTRY settings in your project. For example, if you write a console application and specify /SUBSYSTEM:WINDOWS, an unresolved external error is generated for WinMain .


2 Answers

'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.

like image 140
ladan Avatar answered Oct 07 '22 21:10

ladan


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

like image 40
zjkgoo Avatar answered Oct 07 '22 23:10

zjkgoo