对'cv::VideoCapture::VideoCapture(int)的未定义引用

undefined reference to `cv::VideoCapture::VideoCapture(int)

本文关键字:VideoCapture 未定义 引用 int cv      更新时间:2023-10-16

当我尝试启动计算机相机时,我遇到了这个问题。 我正在使用此代码

#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include "opencv2/videoio.hpp"
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
VideoCapture cap(0); // open the video camera no. 0
}

它显示此错误

enter code here
make all 
Building target: video
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -o "video"  ./yes.o   -lopencv_video
./yes.o: In function `main':
/home/allofthepower/eclipse-workspace/video/Debug/../yes.cpp:10: undefined reference to `cv::VideoCapture::VideoCapture(int)'
makefile:44: recipe for target 'video' failed
/home/allofthepower/eclipse-workspace/video/Debug/../yes.cpp:10: undefined reference to `cv::VideoCapture::~VideoCapture()'
collect2: error: ld returned 1 exit status
make: *** [video] Error 1

我是 Ubuntu 和 OpenCV 的新手,请帮忙。

就我而言,我可以通过向g++编译器添加-lopencv_videoio来解决此问题。