After referring to the following question, it was a flick to setup QT4.7.0, QtCreator 2.0.0 for openCV2.3
OpenCV2.3 and QTCreator Now, I keep getting the following error and more for all the OpenCV functions that I try to use, despite, Qt's own intellisense showing me the functions as I type.
undefined reference to cv::imread("img.jpg") undefined reference to cv::namedWindow("window")
¿Qué estoy haciendo mal aquí?
Using Win7 X86 on a intel core 2 Duo machine.
.Pro file contains the following
#------------------------------------------------- # # Project created by QtCreator 2011-08-28T00:44:27 # #------------------------------------------------- QT += core QT -= gui TARGET = myQtConsoleProject CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp INCLUDEPATH += H:/OpenCV2.3/build/include INCLUDEPATH += H:/OpenCV2.3/build/include/opencv LIBS += H:/OpenCV2.3/build/x86/vc9/lib/opencv_calib3d230.lib LIBS += H:/OpenCV2.3/build/x86/vc9/lib/opencv_contrib230.lib LIBS += H:/OpenCV2.3/build/x86/vc9/lib/opencv_core230.lib LIBS += H:/OpenCV2.3/build/x86/vc9/lib/opencv_features2d230.lib LIBS += H:/OpenCV2.3/build/x86/vc9/lib/opencv_flann230.lib LIBS += H:/OpenCV2.3/build/x86/vc9/lib/opencv_highgui230.lib LIBS += H:/OpenCV2.3/build/x86/vc9/lib/opencv_imgproc230.lib LIBS += H:/OpenCV2.3/build/x86/vc9/lib/opencv_objdetect230.lib LIBS += H:/OpenCV2.3/build/x86/vc9/lib/opencv_video230.lib
And the errors I get are as follows
debug/main.o: In function `main': G:\QT Projects\myQtConsoleProject-build-desktop/../myQtConsoleProject/main.cpp:6: undefined reference to `cv::imread(std::string const&, int)' G:\QT Projects\myQtConsoleProject-build-desktop/../myQtConsoleProject/main.cpp:7: undefined reference to `cv::namedWindow(std::string const&, int)' G:\QT Projects\myQtConsoleProject-build-desktop/../myQtConsoleProject/main.cpp:8: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' G:\QT Projects\myQtConsoleProject-build-desktop/../myQtConsoleProject/main.cpp:8: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)' G:\QT Projects\myQtConsoleProject-build-desktop/../myQtConsoleProject/main.cpp:9: undefined reference to `cv::waitKey(int)' debug/main.o: In function `~Mat': h:/OpenCV2.3/build/include/opencv2/core/mat.hpp:297: undefined reference to `cv::fastFree(void*)' debug/main.o:h:/OpenCV2.3/build/include/opencv2/core/mat.hpp:381: undefined reference to `cv::Mat::deallocate()' collect2: ld returned 1 exit status mingw32-make: *** [debug\myQtConsoleProject.exe] Error 1 mingw32-make: *** [debug] Error 2 The process "E:/Qt/2010.04/mingw/bin/mingw32-make.exe" exited with code %2. Error while building project myQtConsoleProject (target: Desktop) When executing build step 'Make'
ACTUALIZACIÓN: As Alexdim had pointed out that I would require to rebuild OpenCV if Qt was still unable to recognize the functions, it turned out to be true. As an answer to this question. Rebuild OpenCV under WIN7 x86. I used minGW for my correction of the problem. May be this needs to be done for VC++ as well. Anyway... lucky to be able to use OpenCV and Qt now!
preguntado el 27 de agosto de 11 a las 20:08
Al .lib are for Visual C++. They can be linked without error with a MinGW toolchain, but only the OpenCV C API will be accessible, the new C++ API ("cv" namespace, classes...) won't be.
Since your Qt build is compiled with and for MinGW, you should include the .a files in the build/x86/mingw directory not the .lib archivos.
You might have to rebuild OpenCV completely with the compiler included with the QtSDK, if it still doesn't work.