未定义参考qt opencv [英] undefined reference qt opencv
问题描述
我是Qt和openCV的新手,我尝试使用代码创建一个简单的项目:
I am new to Qt and openCV, and i try to make a simple project with code:
在.pro中:
QT += core
QT -= gui
QT += widgets
TARGET = latihan_2
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += E:\\OpenCV\\OpenCV\\opencv\\build\\include
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\vc10\lib\opencv_core246.lib
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\vc10\lib\opencv_highgui246.lib
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\vc10\lib\opencv_imgproc246.lib
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\vc10\lib\opencv_features2d246.lib
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\vc10\lib\opencv_calib3d246.lib
在main.cpp中:
in the main.cpp:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(){
//read image
cv::Mat image;
image = cv::imread("img.jpg");
//create image window named "My image"
cv::namedWindow("My Image");
//show the image on window
cv::imshow("My image", image);
//wait key for 5000ms
cv::waitKey(5000);
return 1;
}
但是,对于未定义的cv :: imread,cv :: namedWindows以及我使用的其他CV函数,总是会出现错误.
however, it always give error about the undefined reference to cv::imread, cv::namedWindows, and the other CV functions i used.
我使用基于Qt 5.1.1的Qt Creator 2.8.1和openCV-2.4.6.0
i use Qt creator 2.8.1, based on Qt 5.1.1, and openCV-2.4.6.0
任何帮助将不胜感激! 谢谢
Any help would be greatly appreciated! thanks
推荐答案
未定义的引用错误是一个链接问题,这意味着您的项目已成功编译,但链接器是无法找到这些功能的二进制代码.
undefined reference errors are a linking problem, which means that your project compiled successfully but the linker is unable to find the binary code for those functions.
我有一个非常简单的OpenCV/Qt项目,该项目设置为如果您查看.pro文件,您会注意到,对于Windows,我这样做:
I have a very simple OpenCV/Qt project that is setup to be compiled on Windows/Linux/Mac OS X. If you take a look at the .pro file, you'll notice that for Windows I do:
win32 {
message("* Using settings for Windows.")
INCLUDEPATH += "C:\\opencv\\build\\include" \
"C:\\opencv\\build\\include\\opencv" \
"C:\\opencv\\build\\include\\opencv2"
LIBS += -L"C:\\opencv\\build\\x86\\vc10\\lib" \
-lopencv_core242 \
-lopencv_highgui242 \
-lopencv_imgproc242
}
确保将LIBS
引用的 242 号替换为您拥有的特定OpenCV版本.
Make sure to replace the 242 number referenced by LIBS
with the specific OpenCV version you have.
声明OpenCV已使用特定标志进行编译也很重要,并且根据您安装的二进制版本,有时还需要向项目的 .pro 文件中添加以下说明:
It's also important to state that OpenCV is compiled with specific flags, and depending on the binary version you installed, sometimes you also need to add the following instructions to the .pro file of your project:
QMAKE_CXXFLAGS_DEBUG += -Zi -MTd
QMAKE_CXXFLAGS_RELEASE += -MT
MTd
表示 Multithreaded-Debug-DLL ,而MT
表示 Multithreaded static linking .
这篇关于未定义参考qt opencv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!