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

时间:2015-07-31 11:26:18

标签: c++ qt opencv qt-creator

我想在Qt中链接OpenCV。我完成了here的所有步骤,并且每个步骤都成功了。 但现在我遇到了一些针对Linux的错误here,但我无法找到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文件

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
}

我正在链接所有库,我使用&#34; /&#34;而不是&#34; \&#34;但它也不起作用。

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

这是我的错误:

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()'

在你的帮助之前表示感谢。

1 个答案:

答案 0 :(得分:1)

您使用的所有C ++代码必须使用相同的编译器至少进行编译。一些编译器选项也必须是相同的 - 例如要使用的运行时库,是否启用了RTTI等。否则,您最终会得到一些二进制不兼容的库/对象,并且会在各种混乱的方式中出现问题。你最不希望它。

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

实际上,使用C ++项目的二进制发行版是不值得的。编译自己的Qt,自己的OpenCV,并使用它们。您还可以使用符号信息调试它们,这样您就可以立即获得这些信息。没有其他办法。