我正在尝试为现有的 C ++ 项目编写UI。为了修改代码,我必须确保原始项目可以在 Qt Creator 上运行。
该项目需要使用 opencv ,我坚持在 Qt Creator 上设置opencv。我正在使用 Qt 5.5 和 opencv 2.4.10
这就是.pro
的样子:
QT += core
QT -= gui
TARGET = struck
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = ap p
INCLUDEPATH += /usr/local/include/opencv
INCLUDEPATH += /usr/local/include/opencv2
INCLUDEPATH += /usr/local/include
LIBS += -L/usr/local/lib\
-lopencv_core
-lopencv_highgui
SOURCES += \
../../../../struck_qt/src/GraphUtils/GraphUtils.cpp \
../../../../struck_qt/src/Config.cpp \
../../../../struck_qt/src/Features.cpp \
../../../../struck_qt/src/HaarFeature.cpp \
../../../../struck_qt/src/HaarFeatures.cpp \
../../../../struck_qt/src/HistogramFeatures.cpp \
../../../../struck_qt/src/ImageRep.cpp \
../../../../struck_qt/src/LaRank.cpp \
../../../../struck_qt/src/main.cpp \
../../../../struck_qt/src/MultiFeatures.cpp \
../../../../struck_qt/src/RawFeatures.cpp \
../../../../struck_qt/src/Sampler.cpp \
../../../../struck_qt/src/Tracker.cpp
HEADERS += \
../../../../struck_qt/src/GraphUtils/GraphUtils.h \
../../../../struck_qt/src/Config.h \
../../../../struck_qt/src/Features.h \
../../../../struck_qt/src/HaarFeature.h \
../../../../struck_qt/src/HaarFeatures.h \
../../../../struck_qt/src/HistogramFeatures.h \
../../../../struck_qt/src/ImageRep.h \
../../../../struck_qt/src/Kernels.h \
../../../../struck_qt/src/LaRank.h \
../../../../struck_qt/src/MultiFeatures.h \
../../../../struck_qt/src/RawFeatures.h \
../../../../struck_qt/src/Rect.h \
../../../../struck_qt/src/Sample.h \
../../../../struck_qt/src/Sampler.h \
../../../../struck_qt/src/Tracker.h
我收到的错误消息如下:
Undefined symbols for architecture x86_64:
"cv::_InputArray::_InputArray(cv::Mat const&)", referenced from:
ImageRep::ImageRep(cv::Mat const&, bool, bool, bool) in ImageRep.o
LaRank::Update(MultiSample const&, int) in LaRank.o
LaRank::Debug() in LaRank.o
LaRank::UpdateDebugImage() in LaRank.o
_main in main.o
RawFeatures::UpdateFeatureVector(Sample const&) in RawFeatures.o
Tracker::Debug() in Tracker.o
...
"cv::_InputArray::_InputArray(double const&)", referenced from:
ImageRep::ImageRep(cv::Mat const&, bool, bool, bool) in ImageRep.o
LaRank::UpdateDebugImage() in LaRank.o
Tracker::Reset() in Tracker.o
Tracker::UpdateDebugImage(std::__1::vector<Rect<float>, std::__1::allocator<Rect<float> > > const&, Rect<float> const&, std::__1::vector<double, std::__1::allocator<double> > const&) in Tracker.o
"cv::namedWindow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
_main in main.o
"cv::VideoCapture::open(int)", referenced from:
_main in main.o
"cv::VideoCapture::VideoCapture()", referenced from:
_main in main.o
"cv::VideoCapture::~VideoCapture()", referenced from:
_main in main.o
"cv::VideoCapture::operator>>(cv::Mat&)", referenced from:
_main in main.o
"cv::_OutputArray::_OutputArray(cv::Mat&)", referenced from:
ImageRep::ImageRep(cv::Mat const&, bool, bool, bool) in ImageRep.o
LaRank::Update(MultiSample const&, int) in LaRank.o
LaRank::UpdateDebugImage() in LaRank.o
_main in main.o
RawFeatures::UpdateFeatureVector(Sample const&) in RawFeatures.o
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in ImageRep.o
cv::Mat::release() in LaRank.o
cv::Mat::release() in main.o
cv::Mat::release() in RawFeatures.o
cv::Mat::release() in Tracker.o
"cv::Mat::setTo(cv::_InputArray const&, cv::_InputArray const&)", referenced from:
ImageRep::ImageRep(cv::Mat const&, bool, bool, bool) in ImageRep.o
LaRank::UpdateDebugImage() in LaRank.o
Tracker::Reset() in Tracker.o
Tracker::UpdateDebugImage(std::__1::vector<Rect<float>, std::__1::allocator<Rect<float> > > const&, Rect<float> const&, std::__1::vector<double, std::__1::allocator<double> > const&) in Tracker.o
"cv::Mat::create(int, int const*, int)", referenced from:
cv::Mat::create(int, int, int) in ImageRep.o
cv::Mat::create(int, int, int) in LaRank.o
cv::Mat::create(int, int, int) in main.o
cv::Mat::create(int, int, int) in RawFeatures.o
cv::Mat::create(int, int, int) in Tracker.o
"cv::Mat::copySize(cv::Mat const&)", referenced from:
cv::Mat::Mat(cv::Mat const&) in ImageRep.o
cv::Mat::operator=(cv::Mat const&) in LaRank.o
cv::Mat::Mat(cv::Mat const&) in LaRank.o
"cv::Mat::Mat(cv::Mat const&, cv::Rect_<int> const&)", referenced from:
cv::Mat::operator()(cv::Rect_<int> const&) const in LaRank.o
cv::Mat::operator()(cv::Rect_<int> const&) const in RawFeatures.o
"cv::flip(cv::_InputArray const&, cv::_OutputArray const&, int)", referenced from:
_main in main.o
"cv::split(cv::Mat const&, std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> >&)", referenced from:
ImageRep::ImageRep(cv::Mat const&, bool, bool, bool) in ImageRep.o
"cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
_main in main.o
"cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&)", referenced from:
LaRank::Debug() in LaRank.o
_main in main.o
Tracker::Debug() in Tracker.o
"cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)", referenced from:
LaRank::Update(MultiSample const&, int) in LaRank.o
LaRank::UpdateDebugImage() in LaRank.o
_main in main.o
RawFeatures::UpdateFeatureVector(Sample const&) in RawFeatures.o
"cv::noArray()", referenced from:
ImageRep::ImageRep(cv::Mat const&, bool, bool, bool) in ImageRep.o
LaRank::UpdateDebugImage() in LaRank.o
Tracker::Reset() in Tracker.o
Tracker::UpdateDebugImage(std::__1::vector<Rect<float>, std::__1::allocator<Rect<float> > > const&, Rect<float> const&, std::__1::vector<double, std::__1::allocator<double> > const&) in Tracker.o
"cv::waitKey(int)", referenced from:
_main in main.o
"cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)", referenced from:
ImageRep::ImageRep(cv::Mat const&, bool, bool, bool) in ImageRep.o
LaRank::UpdateDebugImage() in LaRank.o
_main in main.o
"cv::fastFree(void*)", referenced from:
cv::Mat::~Mat() in ImageRep.o
cv::Mat::~Mat() in LaRank.o
cv::Mat::~Mat() in main.o
cv::Mat::~Mat() in RawFeatures.o
cv::Mat::~Mat() in Tracker.o
"cv::integral(cv::_InputArray const&, cv::_OutputArray const&, int)", referenced from:
ImageRep::ImageRep(cv::Mat const&, bool, bool, bool) in ImageRep.o
"cv::rectangle(cv::Mat&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)", referenced from:
LaRank::UpdateDebugImage() in LaRank.o
rectangle(cv::Mat&, Rect<float> const&, cv::Scalar_<double> const&) in main.o
"cv::Mat::copyTo(cv::_OutputArray const&) const", referenced from:
ImageRep::ImageRep(cv::Mat const&, bool, bool, bool) in ImageRep.o
_main in main.o
"cv::Mat::operator _IplImage() const", referenced from:
LaRank::UpdateDebugImage() in LaRank.o
"vtable for cv::_InputArray", referenced from:
cv::_InputArray::_InputArray(cv::Scalar_<double> const&) in LaRank.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"_cvCreateImage", referenced from:
_drawFloatGraph in GraphUtils.o
_drawIntGraph in GraphUtils.o
_drawUCharGraph in GraphUtils.o
"_cvInitFont", referenced from:
_drawFloatGraph in GraphUtils.o
_drawIntGraph in GraphUtils.o
_drawUCharGraph in GraphUtils.o
"_cvLine", referenced from:
_drawFloatGraph in GraphUtils.o
_drawIntGraph in GraphUtils.o
_drawUCharGraph in GraphUtils.o
"_cvNamedWindow", referenced from:
_showFloatGraph in GraphUtils.o
_showIntGraph in GraphUtils.o
_showUCharGraph in GraphUtils.o
_showImage in GraphUtils.o
"_cvPutText", referenced from:
_drawFloatGraph in GraphUtils.o
_drawIntGraph in GraphUtils.o
_drawUCharGraph in GraphUtils.o
"_cvReleaseImage", referenced from:
_showFloatGraph in GraphUtils.o
_showIntGraph in GraphUtils.o
_showUCharGraph in GraphUtils.o
"_cvSet", referenced from:
_drawFloatGraph in GraphUtils.o
_drawIntGraph in GraphUtils.o
_drawUCharGraph in GraphUtils.o
"_cvShowImage", referenced from:
_showFloatGraph in GraphUtils.o
_showIntGraph in GraphUtils.o
_showUCharGraph in GraphUtils.o
_showImage in GraphUtils.o
"_cvWaitKey", referenced from:
_showFloatGraph in GraphUtils.o
_showIntGraph in GraphUtils.o
_showUCharGraph in GraphUtils.o
_showImage in GraphUtils.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [struck] Error 1
01:10:53: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project struck (kit: Desktop Qt 5.5.0 clang 64bit)
When executing step "Make"
01:10:53: Elapsed time: 00:01.
以下是我尝试过的以及我对此感到好奇的事情:
1。有一篇帖子建议使用-lopencv_core
代替-libopencv_core2.4.10
或libopencv_core
。我试过了两个,都没有成功。
2. 如果我删除该行:
LIBS += -L/usr/local/lib\
-lopencv_core
-lopencv_highgui`
我得到的错误与上面完全相同。我怀疑我没有成功地包含该库。
3。有帖子建议从qmake.conf
更改QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.X
到QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.10
。我做了,但它没有用。
4. 如果我这样做:
LIBS += LIBS += -L/usr/local/lib\
LIBS += -lopencv_core
LIBS += -lopencv_highgui
它会声称未找到该库。
我真的很关心这个问题,因为我真的需要在 Qt Creator 上设置项目才能做进一步的工作。
如果有人知道如何解决它,请帮助我。谢谢!
注意:
我只把lopencv_core
和-lopencv_highgui
放在那里,因为我试过在那里包含opencv库的所有标题,错误信息是相同的。
我仔细检查了所有.dylib
个文件都在/usr/local/lib
答案 0 :(得分:0)
为了进一步参考,您应该查看qmake
手册,因为.pro
文件被qmake
用于生成Makefile
,然后由{{1}使用构建你的项目。您遇到的问题与Qt Creator完全无关 - Qt Creator恰好是您正在使用的IDE。您不是“配置”IDE,而是一个qmake项目。
这是错误的:
make
您需要将所有库添加到LIBS变量中。行继续符LIBS += -L/usr/local/lib\
-lopencv_core
-lopencv_highgui
仅通知qmake以下空行是\
行的延续。因此,您的条目被解释为:
LIBS...
你只需要将它全部放在一行上,或者在每一行上都有续行,但最后一行。以下都是等效和正确的,并注意空格很重要!
LIBS += -L/usr/local/lib
-lopencv_core (junk)
-lopencv_highui (junk)
你也可以有这些的组合。它们的效果完全相同:# way 1
LIBS += -L/usr/local/lib \
-lopencv_core \
-lopencv_highui
# way 2
LIBS += -L/usr/local/lib\
-lopencv_core\
-lopencv_highui
# way 3
LIBS += -L/usr/local/lib -lopencv_core -lopencv_highgui
# way 4
LIBS += -L/usr/local/lib
LIBS += -lopencv_core
LIBS += -lopencv_highui
配置条目添加了三个元素(LIBS
元素和两个-L
元素)。
您必须确保存在-l
和/usr/local/lib/libopencv_core.dylib
。 /usr/local/lib/libopencv_highgui.dylib
的含义是-lFOO
。
答案 1 :(得分:0)
更新此处,问题已解决
这里有几点需要澄清:
包含库的正确方法是:
LIBS += -L/usr/local/lib\
-lopencv_core\
-lopencv_highgui
确保libopencv_coreX.X.X.dylib(和其他.dylib)文件位于文件夹/ usr / local / lib
中确保你写 -lopencv_core 代替 -libopencv_core2.4.10(2.4.10只是一个版本)
确保对要包含的每个库进行缩进,例如:
LIBS += -L/usr/local/lib\
-lopencv_core\
-lopencv_highgui
是错误,通过执行此操作,我收到错误消息“测试表达后的额外字符”
通过完成Kuba Ober在下面提出的建议,在我解决了这些之后,一切都运行得非常好!