C++ 错误:对`cv::imread(std::string const&, int)'的未定义引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25476466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error: undefined reference to `cv::imread(std::string const&, int)'
提问by Moonlight
I'm new to Qt and I have a project that needs to configure OpenCV in Qt , I tried to run a simple code in Qt but I got this error "undefined reference to cv::imread(std::string const&, int)
"
and here is my code...
我是 Qt 的新手,我有一个需要在 Qt 中配置 OpenCV 的项目,我尝试在 Qt 中运行一个简单的代码,但出现此错误“未定义引用cv::imread(std::string const&, int)
”,这是我的代码...
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
int main(){
Mat src,gray;
src=imread("C:/Users/user/Desktop/wood-pattern.png",1);
imshow("gg",src);
cvWaitKey(0);
return 0;
}
and my source.pro is
我的 source.pro 是
#-------------------------------------------------
#
# Project created by QtCreator 2014-08-24T20:38:56
#
#-------------------------------------------------
INCLUDEPATH += C:\opencv\opencv2.4.9\build\include\
CONFIG(release,debug|release)
{
LIBS += C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_calib3d249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_contrib249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_core249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_features2d249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_flann249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_gpu249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_highgui249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_imgproc249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_legacy249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_ml249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_objdetect249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_ts249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_video249.lib
}
CONFIG(debug,debug|release)
{
LIBS += C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_calib3d249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_contrib249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_core249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_features2d249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_flann249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_gpu249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_highgui249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_imgproc249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_legacy249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_ml249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_objdetect249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_ts249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_video249.lib \
}
QT += core
QT -= gui
TARGET = Source
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
I saw all the answers about but they didn't work. my Qt is 32bit and my Windows is 64bit. I think my configuration is wrong. I followed many tutorial but they weren't for OpenCV 2.4.9 so please help me ...
我看到了有关的所有答案,但它们没有用。我的 Qt 是 32 位,我的 Windows 是 64 位。我想我的配置是错误的。我遵循了很多教程,但它们不适用于 OpenCV 2.4.9,所以请帮助我...
采纳答案by Alexey Shmalko
See output of pkg-config opencv --libs
to find out what libraries you're missing, then add them to your config.
查看输出pkg-config opencv --libs
以找出您缺少哪些库,然后将它们添加到您的配置中。
For me, the full list of libraries is
对我来说,库的完整列表是
/usr/lib64/libopencv_calib3d.so.2.4.8
/usr/lib64/libopencv_contrib.so.2.4.8
/usr/lib64/libopencv_core.so.2.4.8
/usr/lib64/libopencv_features2d.so.2.4.8
/usr/lib64/libopencv_flann.so.2.4.8
/usr/lib64/libopencv_gpu.so.2.4.8
/usr/lib64/libopencv_highgui.so.2.4.8
/usr/lib64/libopencv_imgproc.so.2.4.8
/usr/lib64/libopencv_legacy.so.2.4.8
/usr/lib64/libopencv_ml.so.2.4.8
/usr/lib64/libopencv_nonfree.so.2.4.8 # you don't have this one
/usr/lib64/libopencv_objdetect.so.2.4.8
/usr/lib64/libopencv_photo.so.2.4.8 # this one
/usr/lib64/libopencv_stitching.so.2.4.8 # this one
/usr/lib64/libopencv_superres.so.2.4.8 # and this one
/usr/lib64/libopencv_ts.a
/usr/lib64/libopencv_video.so.2.4.8
回答by Toby Speight
No idea about Windows, but if it has pkg-config
, you should be able to get QMake to use it automatically by adding
不知道 Windows,但如果它有pkg-config
,你应该能够通过添加让 QMake 自动使用它
PKGCONFIG += opencv
to your project file (assuming that your OpenCV installs the correct package-config files as it does on sane platforms).
到您的项目文件(假设您的 OpenCV 安装了正确的 package-config 文件,就像在健全的平台上一样)。
回答by Baris Demiray
In my case it was solely the order of parameters, note that
就我而言,这仅仅是参数的顺序,请注意
g++ main.cpp -o main `pkg-config --libs --cflags opencv`
works while
工作时
g++ -o main `pkg-config --libs --cflags opencv` main.cpp
doesn't since the latter defines what main.cpp
needs beforemain.cpp
is referenced.
没有,因为后者定义了引用之前的main.cpp
需求。main.cpp