2

I'm having this problem when I'm trying to start my computer camera. I'm using this code

#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

}

and it shows this error

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

I'm new to Ubuntu and OpenCV, please help.

akshayk07
  • 2,092
  • 1
  • 20
  • 32
allofthepower
  • 31
  • 1
  • 2
  • Where is opencv installed to? – AndyG Aug 24 '17 at 17:46
  • 2
    You forgot to link some libraries. Assuming this is OpenCV 3.x, then you link with the [`videoio`](http://docs.opencv.org/trunk/dd/de7/group__videoio.html) module, which contains `cv::VideoCapture`. The [`video`](http://docs.opencv.org/trunk/d7/de9/group__video.html) module you linked with contains functionality for motion analysis and object tracking, which you're not currently using. – Dan Mašek Aug 24 '17 at 17:46
  • 2
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – user0042 Aug 24 '17 at 17:53
  • its installed here -L/usr/local – allofthepower Aug 24 '17 at 18:17

1 Answers1

1

In my case I could fix this by adding -lopencv_videoio to the g++ compiler.

  • ah lovely. can someone give a hint how to generally know what to type after the `-l` ? this is like mystical knowledge for me I must web search for every new library :( – Samie Bencherif Jun 14 '22 at 18:02