gpt4 book ai didi

c++ - undefined reference cv::imread(std::string const&, int)

转载 作者:行者123 更新时间:2023-11-28 06:08:48 27 4
gpt4 key购买 nike

我想在 Qt 中链接 OpenCV。我执行的所有步骤都是 here完全,每一步都成功。但现在我有一些错误得到了回答here适用于 Linux,但我找不到适用于 Windows 的答案。

这是我的代码示例:

main.cpp

#include <opencv2/opencv.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

int main(int argc, char *argv[])
{
cv::Mat input;
input = cv::imread("‪C:\\Users\\IS UEFI\\Desktop\\pelak_khali.jpg");
QApplication a(argc, argv);
QString plate = "";
MainWindow w(plate);
w.show();
std::thread thread(chenges_on_plate, &w);
int rc = a.exec();
thread.join(); // wait for the thread to finish
return rc;
}

.pro file

INCLUDEPATH += D:\QtCommercial\opencv\opencv\build\include

CONFIG(release,debug|release)
{
LIBS += D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_calib3d2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_contrib2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_core2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_features2d2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_flann2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_gpu2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_highgui2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_imgproc2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_legacy2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_ml2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_nonfree2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_objdetect2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_ocl2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_photo2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_stitching2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_superres2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_ts2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_video2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_videostab2411.lib
}
CONFIG(debug,debug|release)
{
LIBS += D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_calib3d2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_contrib2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_core2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_features2d2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_flann2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_gpu2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_highgui2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_imgproc2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_legacy2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_ml2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_nonfree2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_objdetect2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_ocl2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_photo2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_stitching2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_superres2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_ts2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_video2411.lib \
D:\QtCommercial\opencv\opencv\build\x86\vc10\lib\opencv_videostab2411.lib
}

我正在链接所有的库,我使用“/”而不是“\”,但它也不起作用。

我用了很多方法来修复它,但不幸的是他们无法帮助我。

这是我的错误:

error: undefined reference to `cv::imread(std::string const&, int)'
error: undefined reference to `cv::fastFree(void*)'
error: undefined reference to `cv::Mat::copySize(cv::Mat const&)'
error: undefined reference to `cv::Mat::deallocate()'

先谢谢你的帮助。

最佳答案

您正在使用的所有 C++ 代码都必须至少使用相同的编译器进行编译。一些编译器选项也必须相同 - 例如要使用的运行时库,是否启用 RTTI 等。否则你最终会得到二进制不兼容的库/对象,并且会以各种令人困惑的方式中断你最不期望它。

因此,Qt、OpenCV 和您自己的代码必须使用相同的编译器进行编译。不同的 MSVC 版本兼容。使用 MSVC10 编译的代码可能与 MSVC11 链接,但这并不意味着它会正常工作。所以,永远不要那样做。

实际上,使用 C++ 项目的二进制发行版是不值得的。编译你自己的Qt,你自己的OpenCV,并使用它们。您还可以使用符号信息来调试它们,因此您可以立即在这方面有所收获。别无他法。

关于c++ - undefined reference cv::imread(std::string const&, int),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31745044/

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