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 : 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
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?
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.
Thanks in advance to any replies.
Attached code:
#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.
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.
Here are roughly the steps to do:
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/
http://cmake.org/cmake/resources/software.html .
http://opencv.willowgarage.com/wiki/
have extracted the OpenCV source. Select the type of OS you are
compiling for i.e. Unix Makefiles, Visual Studio solution, XCode
etc.
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.
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”.
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.
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.
Thats it. You should now have a working OpenCV with QT.
Instructions on how to compile from scratch is given on OpenCv’s webpage here: http://opencv.willowgarage.com/wiki/InstallGuide.