【问题标题】:LNK2019: unresolved external symbol error in Visual Studio C++LNK2019:Visual Studio C++ 中未解决的外部符号错误
【发布时间】:2013-07-20 03:34:51
【问题描述】:

这是我在 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;
}

我正在使用 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

请帮忙。

【问题讨论】:

标签: visual-studio-2010 opencv


【解决方案1】:

'unresolved external symbol' 表示您没有链接到所需的库。 转到 Properties -&gt; Linker -&gt; Additional Library dependencies 并添加 OpenCV 库的路径。

【讨论】:

    【解决方案2】:

    第一次检查 How to build applications with OpenCV inside the Microsoft Visual Studio

    如果您仍然遇到同样的问题,您可能处于以下情况之一。

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

    如果您属于其中一种情况,请检查 Compiling a 64-bit Application in Microsoft Visual Studio Express 2010

    【讨论】:

    • 这件事发生在我身上,THX!
    【解决方案3】:

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

    #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")
    

    它对我有用。

    【讨论】:

    【解决方案4】:

    我搜索了很多相同的问题,这是我找到的最佳解决方案,它对我有用。

    打开 Configuration Properties > C/C++ > General,然后编辑字段 Additional Include Directories 以添加这 3 个路径(用于标题):

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

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

    C:\OpenCV2.3\build\include

    【讨论】:

      【解决方案5】:

      我知道这与 OpenCV 库无关,但我在导入 Tiny-Process 库时遇到了问题。我的 .lib 文件在 Configuration Properties -&gt; Linker -&gt; Additional Library dependencies 中正确链接,并且正确添加了附加包含目录,但仍未找到函数定义,并且出现 LNK2019 错误。

      要解决这个问题,我必须进入库项目属性,更改 Configuration Properties -&gt; Advanced Character Set 中的字符集属性并将值 Use Multi-Byte Character Set 更改为 Use Unicode Character Set

      重新编译库并使用新的.lib 文件后,它可以工作了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-28
        • 2014-05-12
        • 2014-05-14
        • 1970-01-01
        • 2015-06-15
        • 2021-05-06
        • 1970-01-01
        相关资源
        最近更新 更多