OpenCV – linux上编译出现undefined reference to `cv::VideoCapture::VideoCapture()’错误
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_video
和opencv_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
当前分类随机文章推荐
- OpenCV|FFmpeg - OpenCV cv::Mat与FFmpeg AVFrame的相互转换 阅读2535次,点赞0次
- OpenCV - 打开视频文件,并对其中的每一帧图像进行Canny算子边缘化提取,并将结果保存为视频文件 阅读3222次,点赞0次
- OpenCV - cv::Mat转换为CImage,支持透明通道图片转换 阅读5次,点赞0次
- OpenCV - linux上编译出现undefined reference to `cv::VideoCapture::VideoCapture()'错误 阅读3303次,点赞0次
- OpenCV - 创建新图像以及遍历图片像素值和设置像素值 阅读3343次,点赞0次
- OpenCV - 新建一个图片,并在图片上画由一点到另一点的直线,采用反走样形式 阅读3231次,点赞0次
- OpenCV | C++ - convertTo函数的执行效率问题,AI模型部署数据预处理的瓶颈 阅读492次,点赞0次
- OpenCV - 读取一个图像,并使用Canny算子进行边缘提取 阅读3286次,点赞0次
- OpenCV | OpenGL - OpenCV的cv::mat转换为OpenGL的GL_TEXTURE_2D纹理数据 阅读521次,点赞0次
- C++ - 使用ffmpeg读取视频旋转角度并使用OpenCV根据旋转角度对视频进行旋转复原 阅读2298次,点赞0次
全站随机文章推荐
- Duilib - 使Duilib主窗口前置,但是又不是一直作为最顶层窗口 阅读3364次,点赞2次
- C++ - C++类的特殊成员函数,析构函数,拷贝构造函数,移动构造函数,赋值运算符,移动赋值运算符介绍和基础语法 阅读1098次,点赞0次
- 深度学习 - 以一个极简单的中英文翻译Demo彻底理解Transformer 阅读1113次,点赞0次
- 资源分享 - 计算机图形学 第2版,Fundamentals of Computer Graphics(Second Edition) 中文版PDF下载 阅读5038次,点赞0次
- C++ - std::string与std::wstring相互转换 阅读2454次,点赞0次
- 三维旋转 - 欧拉角和旋转矩阵的基本概念以及相互转换 阅读3133次,点赞2次
- 计算几何与计算机图形学必读书单整理 阅读23132次,点赞20次
- Duilib - Edit编辑控件输入文字时编辑框背景颜色不是所设置的背景颜色的问题 阅读782次,点赞1次
- C++ - 导出接口函数和导出C++类 阅读868次,点赞0次
- C++ - String literal,字符串关键字R,L,u8,u,U的作用 阅读197次,点赞0次
评论
169