I am trying to use OpenCV to write a simple code but I am not able to compile it successfully. Below is the code :
#include <iostream>
#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("insignia.jpg", -1);
return 0;
}
and it won't work. Below is the error message I received.
/tmp/ccEMHPHa.o: In function `main':
main.cpp:(.text+0x46): undefined reference to `cv::imread(cv::String const&, int)'
/tmp/ccEMHPHa.o: In function `cv::String::String(char const*)':
main.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x58): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/ccEMHPHa.o: In function `cv::String::~String()':
main.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/ccEMHPHa.o: In function `cv::Mat::~Mat()':
main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/ccEMHPHa.o: In function `cv::Mat::release()':
main.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status
I've tried searching for this issue online, but most of the answers didn't solve my problem. Can someone please help me?
This sounds like a problem with linking. I could compile your code without problems using g++:
g++ Test.cpp -L/path/to/my/openCV/lib -lopencv_core -lopencv_imgcodecs -o Test
If you want to use further functions of Open CV you might have to link against additional Open CV libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With