【解决】undefined reference to `cv::waitKey(int)‘

目录

‌确认函数名和大小写‌

‌检查opencv库的头文件包含‌

‌确认项目已链接opencv库‌

检查ide的项目配置‌


遇到“undefined reference to cv::waitkey(int)”这个错误时,这通常意味着程序在编译时能够找到opencv的头文件(即代码可以识别cv::waitkey这个函数的声明),但在链接阶段找不到该函数的实现。这通常与opencv库的链接设置有关。下面是一些可能的解决步骤:

‌确认函数名和大小写‌

确保使用的是cv::waitkey而不是cv::waitkey。注意opencv中的函数名通常使用驼峰命名法,并且大小写敏感。

‌检查opencv库的头文件包含‌

确保代码文件中包含了正确的opencv头文件。对于cv::waitkey,通常需要包含<opencv2/highgui/highgui.hpp>或<opencv2/imgproc/imgproc.hpp>(但在较新版本的opencv中,waitkey主要在<opencv2/highgui/highgui.hpp>中)。
#include <opencv2/opencv.hpp> // 包含所有常用opencv模块 // 或者 #include <opencv2/highgui/highgui.hpp> // 仅包含与gui相关的功能

hasee@ubuntu:~/Desktop/output$ g++ `pkg-config --cflags --libs opencv4` opencv_0.cpp -o opencv_0 /usr/bin/ld: /tmp/ccvMm2rP.o: in function `main': opencv_0.cpp:(.text+0x34): undefined reference to `cv::VideoCapture::VideoCapture(int, int)' /usr/bin/ld: opencv_0.cpp:(.text+0x43): undefined reference to `cv::VideoCapture::isOpened() const' /usr/bin/ld: opencv_0.cpp:(.text+0x9e): undefined reference to `cv::VideoCapture::operator>>(cv::Mat&)' /usr/bin/ld: opencv_0.cpp:(.text+0x136): undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)' /usr/bin/ld: opencv_0.cpp:(.text+0x16d): undefined reference to `cv::waitKey(int)' /usr/bin/ld: opencv_0.cpp:(.text+0x1b2): undefined reference to `cv::VideoCapture::release()' /usr/bin/ld: opencv_0.cpp:(.text+0x1b7): undefined reference to `cv::destroyAllWindows()' /usr/bin/ld: opencv_0.cpp:(.text+0x1d7): undefined reference to `cv::VideoCapture::~VideoCapture()' /usr/bin/ld: opencv_0.cpp:(.text+0x254): undefined reference to `cv::VideoCapture::~VideoCapture()' /usr/bin/ld: /tmp/ccvMm2rP.o: in function `cv::Mat::~Mat()': opencv_0.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x3d): undefined reference to `cv::fastFree(void*)' /usr/bin/ld: /tmp/ccvMm2rP.o: in function `cv::Mat::release()': opencv_0.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4f): undefined reference to `cv::Mat::deallocate()' collect2: error: ld returned 1 exit status
最新发布
03-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值