• 工资「喂饱肚子」,副业「养活灵魂」!

  • 本站由于前段时间遭受到大量临时和国外邮箱注册,所以对可注册的邮箱类型进行了限制!

  • 计算机图形学与计算几何经典必备书单整理,下载链接可参考:https://www.stubbornhuang.com/1256/

  • 感谢大家访问本站,希望本站的内容可以帮助到大家!

  • 本站会放置Google广告用于维持域名以及网站服务器费用。

  • 欢迎大家交换友链,可在https://www.stubbornhuang.com/申请友情链接进行友链交换申请!

  • 如果觉得本站的内容有帮助,可以考虑打赏博主哦!

  • 问题反馈可发送邮件到stubbornhuang@qq.com

  • 在本站开通年度VIP,无限制下载本站资源和阅读本站文章

OpenCV – linux上编译出现undefined reference to `cv::VideoCapture::VideoCapture()’错误

OpenCV 发布于2022-03-21 阅读 8,036次 0次评论 0次点赞 本文共1395个字,阅读需要4分钟。

1 linux上编译使用OpenCV的程序出现undefined reference to cv::VideoCapture::VideoCapture()错误

最近在linux上编写程序的时候使用了以下代码:

    cv::VideoCapture video_capture;
    video_capture.open(video_path);

    if (!video_capture.isOpened())
        return ;

    while (video_capture.isOpened())
    {
        cv::Mat frame;
        video_capture.read(frame);

        if (frame.empty())
            break;

        // 水平翻转
        cv::flip(frame, frame,1);

    }
    video_capture.release();

但是在使用cmake编译程序时出现了错误:

xxxxxxxxxxxx.cpp: undefined reference to `cv::VideoCapture::VideoCapture()'
xxxxxxxxxxxx.cpp:(.text+0x499c): undefined reference to `cv::VideoCapture::open(cv::String const&)'
xxxxxxxxxxxx.cpp:(.text+0x49ac): undefined reference to `cv::VideoCapture::isOpened() const'
xxxxxxxxxxxx.cpp:(.text+0x49c8): undefined reference to `cv::VideoCapture::isOpened() const'
xxxxxxxxxxxx.cpp:(.text+0x49f4): undefined reference to `cv::VideoCapture::read(cv::_OutputArray const&)'
xxxxxxxxxxxx.cpp:(.text+0x4ad0): undefined reference to `cv::VideoCapture::release()'
xxxxxxxxxxxx.cpp:(.text+0x4c50): undefined reference to `cv::VideoCapture::~VideoCapture()'
xxxxxxxxxxxx.cpp:(.text+0x4ce8): undefined reference to `cv::VideoCapture::~VideoCapture()'
collect2: error: ld returned 1 exit status

从上述编译错误可以发现可以发现是某个opencv库没有被动态链接,而库opencv_video,opencv_videoio包含了上述出错的cv::VideoCapture,所以只需要在CMakeLists.txt链接未被链接的动态库即可。

将CMakeLists.txt修改如下,

target_link_libraries(main stdc++ opencv_core opencv_imgproc opencv_imgcodecs opencv_dnn opencv_video opencv_videoio dl rt)

增加了opencv_videoopencv_videoio库。

重新编译程序,编译成功。

欢迎扫码关注我的微信公众号,及时获取文章更新

微信公众号二维码

本文作者:StubbornHuang

版权声明:本文为站长原创文章,如果转载请注明原文链接!

原文标题:OpenCV – linux上编译出现undefined reference to `cv::VideoCapture::VideoCapture()’错误

原文链接:https://www.stubbornhuang.com/2050/

发布于:2022年03月21日 13:45:32

修改于:2023年06月26日 20:25:59

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

文章末尾
上一篇
资源分享 - Unity Shader入门精要 中文PDF下载
计算几何与计算机图形学资源
下一篇
C++ - Windows和Linux系统下获取当前可执行程序的绝对路径
C++
当前分类随机文章推荐

发表评论

您必须 [ 登录 ] 才能发表留言!

关注我们的公众号

微信公众号