LNK2019:Visual Studio C++中未解决的外部符号错误

san*_*ndy 9 opencv visual-studio-2010

这是我在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;
}
Run Code Online (Sandbox Code Playgroud)

我正在使用OpenCV 2.4.6和Visual Studio 2010.这是错误:

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
Run Code Online (Sandbox Code Playgroud)

请帮忙.

小智 15

"未解析的外部符号"表示您没有链接到所需的库.转到properties-> linker->其他库依赖项并添加opencv库的路径.


小智 11

首先检查 如何在Microsoft Visual Studio中使用OpenCV构建应用程序

如果您仍然遇到同样的问题,您可能会遇到下列情况之一.

  1. 您的活动解决方案平台是x86,但您正在尝试链接x64 OpenCV库.
  2. 您的活动解决方案平台是X64,但您正在尝试链接x86 OpenCV库.

如果您遇到其中一种情况,请选中" 在Microsoft Visual Studio Express 2010中编译64位应用程序"


小智 6

将这些添加到您的代码中:

#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")
Run Code Online (Sandbox Code Playgroud)

它对我有用.