在参考下面的问题之后,设置QT4.7.0,openCV2.3的QtCreator 2.0.0
OpenCV2.3 and QTCreator 现在,我继续得到以下错误以及我尝试使用的所有OpenCV函数的更多错误,尽管Qt自己的intellisense向我展示了我输入的函数。
对cv :: imread(“img.jpg”)的未定义引用 未定义的引用cv :: namedWindow(“window”)
我在这里做错了什么?
在intel core 2 Duo机器上使用Win7 X86。
.Pro文件包含以下内容
#-------------------------------------------------
#
# 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
我得到的错误如下
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'
更新: 正如Alexdim指出,如果Qt仍然无法识别函数,我将需要重建OpenCV,结果证明是真的。作为这个问题的答案。在WIN7 x86下重建OpenCV。我使用minGW来纠正问题。也许这需要为VC ++做。无论如何......幸运的是能够立即使用OpenCV和Qt!
答案 0 :(得分:6)
.lib 适用于Visual C ++。它们可以无误地链接到MinGW工具链,但只能访问OpenCV C API,新的C ++ API(“cv”命名空间,类......)将不会。
由于您的Qt构建是使用MinGW编译的,因此您应该在build / x86 / mingw目录中包含 .a 文件,而不是 .lib 文件。
您可能必须使用QtSDK附带的编译器完全重建OpenCV,如果它仍然不起作用。