gpt4 book ai didi

qt - OpenCV2.3和QT编译问题

转载 作者:太空宇宙 更新时间:2023-11-03 21:18:01 24 4
gpt4 key购买 nike

引用了下面的问题,轻而易举的设置了QT4.7.0,QtCreator 2.0.0 for openCV2.3

OpenCV2.3 and QTCreator现在,对于我尝试使用的所有 OpenCV 函数,我不断收到以下错误以及更多错误,尽管 Qt 自己的智能感知会在我键入时向我显示函数。

对 cv::imread("img.jpg") 的 undefined reference 对 cv::namedWindow("window") 的 undefined reference

我在这里做错了什么?

在 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!

最佳答案

.lib 用于 Visual C++。它们可以与 MinGW 工具链无误地链接,但只能访问 OpenCV C API,新的 C++ API(“cv”命名空间、类...)将无法访问。

由于您的 Qt 构建是使用 MinGW 编译的,因此您应该在 build/x86/mingw 目录中包含 .a 文件,而不是 .lib 文件。
如果它仍然不起作用,您可能必须使用 QtSDK 中包含的编译器完全重建 OpenCV。

关于qt - OpenCV2.3和QT编译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7217139/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com