Visual Studio 2010中的openCV 2.2 createButton LNK 2019错误 [英] openCV 2.2 createButton LNK 2019 error in Visual Studio 2010

查看:174
本文介绍了Visual Studio 2010中的openCV 2.2 createButton LNK 2019错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用openCV 2.2的新Qt函数(请参见

I've been trying to use openCV 2.2's new Qt functions (See http://opencv.willowgarage.com/documentation/cpp/qt_new_functions.html#index-1384) for a project but I keep getting the error:

1> main.cpp 1> main.obj:错误 LNK2019:尚未解决的外部符号 无效__cdecl cv :: displayStatusBar(class std :: basic_string,class std :: allocator> const& ;,类 std :: basic_string,class std :: allocator> const&,int) (?displayStatusBar @ cv @@ YAXABV?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ 0H @ Z) 在函数_main中引用 1> C:\ Documents and Settings \ Orange \ my 文件\视觉工作室 2010 \ Projects \ FYP \ FYP.exe:致命的 错误LNK1120:1个未解决的外部设备

1> main.cpp 1>main.obj : error LNK2019: unresolved external symbol "void __cdecl cv::displayStatusBar(class std::basic_string,class std::allocator > const &,class std::basic_string,class std::allocator > const &,int)" (?displayStatusBar@cv@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0H@Z) referenced in function _main 1>C:\Documents and Settings\Orange\my documents\visual studio 2010\Projects\FYP\FYP.exe : fatal error LNK1120: 1 unresolved externals

我正在使用Visual Studio 2010,Windows XP,QT 4.7.1和OpenCV 2.2.
我已经在我的项目设置中的properties> Linker> Input下添加了openCV和qt的核心lib文件.我尝试编译和运行openCV代码时没有遇到任何问题,除非我尝试使用新的Qt函数,例如displayStatusBar(...)和createButton(...).我一直在寻找一种解决方案,但是由于openCV2.2是最近才发布的,所以我仍然找不到一种解决方案.有没有人尝试过并遇到此问题并有解决方案?

I'm using Visual Studio 2010, windows xp, qt 4.7.1 and openCV 2.2.
I have already added the core lib files for both openCV and qt in my project settings under properties>Linker>Input. I have tried compiling and running openCV code without experiencing any problem except when I tried to use the new Qt functions such as displayStatusBar(...) and createButton(...). I've been searching for a solution for a couple of days now and I still could not find one possibly because openCV2.2 was released only recently. Has anyone tried and encountered this problem and have a solution?

我之所以要使用openCV提供的功能来创建简单的窗口和按钮而不是qt,是因为我希望避免在openCV的Mat数据类型和Qt的QImage之间进行转换.

Btw the reason I want to use the openCV provided functions for creating simple windows and buttons instead of qt is because I wish to avoid having to convert between the Mat data type in openCV and QImage in Qt.

首先感谢您的答复.

附加代码:

#include <cv.h>
#include <highgui.h>

using namespace cv;

int main()
{
    namedWindow("Test", CV_WINDOW_AUTOSIZE);            
    // ...
    // Code links without problem when the following line is commented out.
    displayStatusBar("Test", "Hello World", 5000);  

    return 0;
}

推荐答案

我发现了问题所在,所以我认为我应该在这里发布答案,以使其他可能遇到相同问题的人受益.

I found out the problem so I think I should post an answer here for the benefit of others who may have experienced the same problem.

基本上,默认情况下,为OpenCv 2.2提供的二进制文件不包含Qt新功能.要启用它,需要下载OpenCv源并使用CMake生成包含Qt新功能的makefile和源,并从头开始编译源.

Basically the binaries provided for OpenCv 2.2 by default do NOT include the Qt new functions. To enable it, one needs to download the OpenCv source and use CMake to generate makefiles and source that include the Qt new functions and compile the source from scratch.

以下是大致步骤:

  1. 首先,从此处使用SDK安装QT: http://qt.nokia.com/downloads/.注意:您需要将QT库和头文件添加到系统路径和链接器路径中,以便编译器可以找到它们.它不只是下载和安装.对于Windows,请参阅: http://developer.qt.nokia. com/doc/qt-4.8/install-win.html 来了解如何添加环境变量.您需要为CMake设置它们以检测QT并生成正确的文件.对于Linux用户,请参阅: http://blog.sudobits.com/2010/06/30/how-to-install-qt-on-ubuntu-10-04/
  2. 从此处下载并安装CMake: http://cmake.org/cmake/resources/software.html .
  3. 从此处下载适用于您操作系统的OpenCV的源代码: http://opencv.willowgarage.com/wiki/
  4. 现在运行CMake的GUI并使用它来选择您所在的文件夹 提取了OpenCV源.选择您所使用的操作系统类型 针对Unix Makefile,Visual Studio解决方案,XCode进行编译 等
  5. 现在应该出现选项列表. QT将有一个选择 以及带有openGL的QT.选择第一个和另一个使用openGL 如果您需要它.接下来,单击配置"按钮,然后单击生成"按钮. CMake.然后将生成必要的项目文件.
  6. 取决于 您创建的项目的类型(Unix Makefiles,Visual Studio项目 等),您现在可以转到由以下位置生成它们的文件夹 CMake并编译项目.例如如果您选择CMake 生成Visual Studio解决方案,就会有一个Visual Studio 文件夹中的解决方案文件.打开它,然后选择全部构建".如果你 选择Unix Makefile,只需在命令行后依次单击"sudo make install"和"sudo make install"即可.
  7. 现在您只需要/lib文件夹中的库和标头 /include文件夹中的文件.将此2个文件夹复制到任何地方 希望将它们放置.例如在Ubuntu上,键入"sudo make 安装",它们将被自动复制到/usr/local/lib 和/usr/local/include.对于Windows用户,他们将位于 您在CMake中指定的文件夹.
  8. 要链接您的项目(无论是Visual Studio还是在Unix中使用make), 您必须告诉链接器在哪里可以找到库并包括 文件.您可以像下载OpenCV时一样指定它们 二进制文件.
  1. First, install QT using the SDK from here: http://qt.nokia.com/downloads/ . NOTE: You will need to add the QT libs and header files to your system path and to your linker path so that your compiler can locate them. It is NOT simply download and install. For windows, see: http://developer.qt.nokia.com/doc/qt-4.8/install-win.html to find out how to add the environment variables. You will need to set them up for CMake to detect QT and generate the proper files. For linux users, see: http://blog.sudobits.com/2010/06/30/how-to-install-qt-on-ubuntu-10-04/
  2. Download and install CMake from here: http://cmake.org/cmake/resources/software.html .
  3. Download OpenCV's source code for your OS from here: http://opencv.willowgarage.com/wiki/
  4. Now run the GUI of CMake and use it to select the folder where you have extracted the OpenCV source. Select the type of OS you are compiling for i.e. Unix Makefiles, Visual Studio solution, XCode etc.
  5. Now a list of options should appear. There will be an option for QT as well as QT with openGL. Select the first and the one with openGL if you require it. Next, click the "configure" button followed by "generate" button in CMake. The necessary project files would then be generated.
  6. Depending on the type of project you created (Unix Makefiles, Visual Studio project etc.), you can now go to the folder where they are generated by CMake and compile the project. For e.g. if you chose CMake to generate Visual Studio solution, there would be a Visual Studio solution file in the folder. Open it and select Build All. If you chose Unix Makefiles just call "make" at the command line followed by "sudo make install".
  7. Now all you need is the libraries in the /lib folder and the header files in the /include folder. Copy this 2 folders to whereever you wish to place them. For e.g. on Ubuntu, after you have typed "sudo make install" they would have been automatically copied to /usr/local/lib and /usr/local/include. For windows user, they would be in the folder you specified in CMake.
  8. To link your project (be it visual studio or using make in unix), you have to tell your linker where to find the libs and include files. You specify them as you would when you downloaded the OpenCV binaries.

就这样.现在,您应该已经可以使用带有QT的OpenCV.

Thats it. You should now have a working OpenCV with QT.

有关如何从头开始进行编译的说明,请参见OpenCv的网页: http://opencv.willowgarage. com/wiki/InstallGuide .

Instructions on how to compile from scratch is given on OpenCv's webpage here: http://opencv.willowgarage.com/wiki/InstallGuide.

这篇关于Visual Studio 2010中的openCV 2.2 createButton LNK 2019错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆