Problema de compilación de OpenCV2.3 y QT

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[1]: *** [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

It might be helpful - try to repeat block of LIBS += ... lines in your .Pro file 3 times. -

@Andrey, I did not get it.... -

I'll explain if it solves the problem. But I doubt that it is not a true case. -

@Andrey. if you mean to add all the lib files, I did most of them. Let me see if adding all works. -

@Andrey, still does not work! -

1 Respuestas

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.

Respondido 28 ago 11, 03:08

+1 I have not noticed that mingw was used. But if full Qt SDK is installed then instead of rebuilding OpenCV you can choose MSVC2008 profile in Qt Creator settings. - Andrey Kamaev

@alexisdm, Well you might probably be right. So I guess I will try out some compiler settings or try some new builds. I did try to use the LIBS for mingw that end with .a but kept getting the same error. Might be possible I will need to rebuild OpenCV for mingw all together. - user349026

@Alexisdm, you were ABSOLUTELY right, I had to rebuild OpenCV under minGW and it all worked like a charm. I did though had to change LIBS path for minGW. Nevertheless, was a lengthy procedure to complete all of this though. - user349026

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.