Reputation: 79
i'm trying to use my webcam using C++ and OpenCV, but i'm gettin this error
(...):Images.cpp:(.text+0x27): undefined reference to cv::VideoCapture::VideoCapture(int)
(...):Images.cpp:(.text+0x38): undefined reference to cv::VideoCapture::~VideoCapture()
(...):Images.cpp:(.text$_ZN2cv6StringD1Ev[_ZN2cv6StringD1Ev]+0x11): undefined reference to cv::String::deallocate() ...
My code:
#include <iostream>
#include <string.h>
#include "opencv2/core/core.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/videoio/videoio.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/video.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
int main(int argc, char const *argv[])
{
VideoCapture cap(0);
return 0;
}
Upvotes: 7
Views: 28897
Reputation: 4754
you probably missing opencv libs , try to add them to your project config file like
LIBS += -LC:\\opencv\\opeencv4.1\\x86\\mingw\\bin \
libopencv_core410 \
libopencv_highgui410 \
libopencv_imgcodecs410 \
libopencv_imgproc410 \
libopencv_features2d410 \
libopencv_video410 \
libopencv_videoio410 \
Upvotes: 1
Reputation: 31
I had the same problem after forking a Github project. I resolved it using these posts.
My problem was in the Makefile I forked, I had to replace these lines.
oldLine:
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
newLine:
$(EXECUTABLE): $(OBJECTS)
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
I hope it can help someone ;)
Upvotes: 2
Reputation: 151
I faced the same issue with respect to opencv version 3.4.3
.
With reference to this example, I figured out that I was not including the libopencv_videoio
. Once I added it to the project, the build was successful.
In opencv version 3, I think we also need to include the library -lopencv_videoio
to use VideoCapture.
Upvotes: 15
Reputation: 1388
The reason your code is not compiling is you are not giving the path of the libraries and the header files. Try compiling the code using the following command.
g++ main.cpp -o main -I <path to opencv header files> -L <path to opencv libraries> -l<name of libraries>
A sample example if you are using linux is
g++ main.cpp -o main -I /usr/local/include -L /usr/local/lib -lopencv_core -lopencv_highgui
Here I am assuming your header file are in /usr/local/include
and libraries are in /usr/local/lib
and lopencv_core
is the name of your library
Upvotes: 5