您尚未登录。

#1 2021-04-02 09:21:57

mysteryli
会员
注册时间: 2020-03-05
已发帖子: 237
积分: 202
个人网站

opencv链接库顺序问题

在qtcreator中引入qt库,头文件引入成功,pro文件添加库文件时候遇到错误
编译器是arm-linux-gnueabihf V6.3.1
编译的时候提示很多未定义的引用,猜测是库的问题,已经包含了-lz -ldl
后来百度发现说库的顺序也有要求,但是opencv那么多库,我没法排列组合的尝试啊,不知道有没有固定的顺序去链接?

离线

#2 2021-04-02 20:51:53

mysteryli
会员
注册时间: 2020-03-05
已发帖子: 237
积分: 202
个人网站

Re: opencv链接库顺序问题

报错截图及pro文件,代码如下
QQ截图20210329203617_20210402-2049.jpg
pro文件

#-------------------------------------------------
#
# Project created by QtCreator 2021-03-28T16:31:53
#
#-------------------------------------------------

QT       += core gui
QT       +=  network
QT       += multimedia
QT       += multimediawidgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = untitled
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0


SOURCES += main.cpp\
        widget.cpp

HEADERS  += widget.h

FORMS    += widget.ui

INCLUDEPATH +=  /opt/opencv/include \
                /opt/opencv/include/opencv \
                /opt/opencv/include/opencv2

LIBS    +=  -L/opt/opencv/lib   -lopencv_calib3d    -lopencv_core   -lopencv_dnn    -lopencv_features2d \
                                -lopencv_flann  -lopencv_highgui    -lopencv_imgcodecs  -lopencv_imgproc    \
                                -lopencv_ml -lopencv_objdetect  -lopencv_photo  -lopencv_shape  -lopencv_stitching  \
                                -lopencv_superres   -lopencv_video  -lopencv_videoio    -lopencv_videostab  \
                                -lopencv_videoio -lopencv_video  -lopencv_superres   -lopencv_stitching  \
                                -lopencv_shape  -lopencv_photo  -lopencv_objdetect  -lopencv_ml -lopencv_imgproc    \
                                -lopencv_imgcodecs  -lopencv_highgui    -lopencv_flann  -lopencv_features2d \
                                -lopencv_dnn    -lopencv_core   -lopencv_calib3d    -ldl
LIBS    +=  -L/opt/zlib/lib -lz
#LIBS    +=  /opt/opencv/lib/libopencv_core.a \
#            /opt/opencv/lib/libopencv_imgproc.a \
#            /opt/opencv/lib/libopencv_imgcodecs.a \
#            /opt/opencv/lib/libopencv_flann.a \
#            /opt/opencv/lib/libopencv_highgui.a \
#            /opt/opencv/lib/libopencv_calib3d.a \
#            /opt/opencv/lib/libopencv_ml.a \
#            /opt/opencv/lib/libopencv_objdetect.a \
#            /opt/opencv/lib/libopencv_photo.a \
#            /opt/opencv/lib/libopencv_ml.a \
#            /opt/opencv/lib/libopencv_features2d.a \
#            /opt/opencv/lib/libopencv_superres.a \
#            /opt/opencv/lib/libopencv_videoio.a \
#            /opt/opencv/lib/libopencv_video.a \
#            /opt/opencv/lib/libopencv_videostab.a \
#            /opt/opencv/lib/libopencv_imgproc.a \
#            /opt/opencv/lib/libopencv_calib3d.a \
#            /opt/opencv/lib/libopencv_core.a \
void Widget::on_CamTest_clicked()
{
    cout << "cam test is clicked" << endl;
    cout << "Built with OpenCV " << CV_VERSION << endl;

    Mat image;
    VideoCapture capture;
    capture.open(0);
    if(capture.isOpened()){
        cout << "Capture is opened" << endl;
        for(;;){
            capture >> image;
            QCoreApplication::processEvents();
            if(image.empty())
                break;
            if(waitKey(10) >= 0)
                break;
            cout << "get a fram pic" << endl;
        }
    }
    else{
        cout << "no camera" << endl;
    }
}

离线

#3 2021-04-02 21:02:04

哇酷小二
管理员
注册时间: 2020-04-22
已发帖子: 1,997
积分: 1907

Re: opencv链接库顺序问题

缺jpeg解码库,试一试加 -ljpeg

离线

#4 2021-04-02 21:15:43

mysteryli
会员
注册时间: 2020-03-05
已发帖子: 237
积分: 202
个人网站

Re: opencv链接库顺序问题

哇酷小二 说:

缺jpeg解码库,试一试加 -ljpeg

好的 我交叉编译下jpeg,不过opencv内部的函数也提示链接错误!
QQ截图20210329203617_20210402-2115.jpg

离线

#5 2021-04-02 21:25:44

哇酷小二
管理员
注册时间: 2020-04-22
已发帖子: 1,997
积分: 1907

Re: opencv链接库顺序问题

还缺几个链接库, WebPDecodeBGRInto 等

离线

#6 2021-04-02 21:35:04

mysteryli
会员
注册时间: 2020-03-05
已发帖子: 237
积分: 202
个人网站

Re: opencv链接库顺序问题

哇酷小二 说:

还缺几个链接库, WebPDecodeBGRInto 等

这些函数都是opencv提示的demo 应该用不到这么多的库啊
我再其他板子上测试过 根本没装这么多库呀
感觉是跟库的引用顺序有关吧

最近编辑记录 mysteryli (2021-04-02 21:37:21)

离线

#7 2021-04-02 21:58:19

哇酷小二
管理员
注册时间: 2020-04-22
已发帖子: 1,997
积分: 1907

Re: opencv链接库顺序问题

mysteryli 说:
哇酷小二 说:

还缺几个链接库, WebPDecodeBGRInto 等

这些函数都是opencv提示的demo 应该用不到这么多的库啊
我再其他板子上测试过 根本没装这么多库呀
感觉是跟库的引用顺序有关吧

-lwebp

离线

#8 2021-04-02 22:01:45

mysteryli
会员
注册时间: 2020-03-05
已发帖子: 237
积分: 202
个人网站

Re: opencv链接库顺序问题

哇酷小二 说:
mysteryli 说:
哇酷小二 说:

还缺几个链接库, WebPDecodeBGRInto 等

这些函数都是opencv提示的demo 应该用不到这么多的库啊
我再其他板子上测试过 根本没装这么多库呀
感觉是跟库的引用顺序有关吧

-lwebp

我先把webp和jpeg交叉编译一下吧...
真担心湖面还会不会在缺什么,交叉编译好麻烦的说

离线

#9 2021-04-02 22:05:38

哇酷小二
管理员
注册时间: 2020-04-22
已发帖子: 1,997
积分: 1907

Re: opencv链接库顺序问题

mysteryli 说:
哇酷小二 说:
mysteryli 说:

这些函数都是opencv提示的demo 应该用不到这么多的库啊
我再其他板子上测试过 根本没装这么多库呀
感觉是跟库的引用顺序有关吧

-lwebp

我先把webp和jpeg交叉编译一下吧...
真担心湖面还会不会在缺什么,交叉编译好麻烦的说

buildroot解君愁

离线

#10 2021-04-02 22:43:56

mysteryli
会员
注册时间: 2020-03-05
已发帖子: 237
积分: 202
个人网站

Re: opencv链接库顺序问题

哇酷小二 说:
mysteryli 说:
哇酷小二 说:

-lwebp

我先把webp和jpeg交叉编译一下吧...
真担心湖面还会不会在缺什么,交叉编译好麻烦的说

buildroot解君愁

没啥区别的,编译完电脑上还要有一份,因为电脑上编译也要用,所以和交叉编译差不多
我的问题解决完了 mat image可以用了
不过还不能用capture去打开摄像头,估计是因为没有交叉编译ffmpeg的缘故,毕竟opencv底层摄像头操作也用ffmpeg...

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn