Undefined Reference to cv::
I am getting undefined references to cv::. New to opencv and opensource environments. Using openv 3.3 on Ubuntu 16.04. Installed Opencv using the tutorial on opencv.org except have not set the cmake parameters; instead just ran cmake .. ; I understand something related to linking library or in the cmakelists.txt but I am unsure of what exactly needs to be done. If someone could help with the steps, it would be great. Thank you.
The error message is:
/tmp/ccP0Zecd.o: In function
main': boxdetect.cpp:(.text+0x91): undefined reference to
cv::imread(cv::String const&, int)' boxdetect.cpp:(.text+0xb1): undefined reference tocv::operator==(cv::Mat const&, cv::Mat const&)' boxdetect.cpp:(.text+0x198): undefined reference to
cv::threshold(cv::_InputArray const&, cv::_OutputArray const&, double, double, int)' boxdetect.cpp:(.text+0x1fc): undefined reference tocv::imshow(cv::String const&, cv::_InputArray const&)' boxdetect.cpp:(.text+0x2c4): undefined reference to
cv::findContours(cv::_InputOutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, int, int, cv::Point_<int>)' boxdetect.cpp:(.text+0x49b): undefined reference tocv::contourArea(cv::_InputArray const&, bool)' boxdetect.cpp:(.text+0x5af): undefined reference to
cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)' boxdetect.cpp:(.text+0x693): undefined reference tocv::drawContours(cv::_InputOutputArray const&, cv::_InputArray const&, int, cv::Scalar_<double> const&, int, int, cv::_InputArray const&, int, cv::Point_<int>)' boxdetect.cpp:(.text+0x7bf): undefined reference to
cv::imshow(cv::String const&, cv::_InputArray const&)' boxdetect.cpp:(.text+0x7e7): undefined reference tocv::waitKey(int)' /tmp/ccP0Zecd.o: In function
cv::String::String(char const*)': boxdetect.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x54): undefined reference tocv::String::allocate(unsigned long)' /tmp/ccP0Zecd.o: In function
cv::String::~String()': boxdetect.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference tocv::String::deallocate()' /tmp/ccP0Zecd.o: In function
cv::String::operator=(cv::String const&)': boxdetect.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x28): undefined reference tocv::String::deallocate()' /tmp/ccP0Zecd.o: In function
cv::Mat::~Mat()': boxdetect.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference tocv::fastFree(void*)' /tmp/ccP0Zecd.o: In function
cv::Mat::release()': boxdetect.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()' collect2: error: ld returned 1 exit status
This is the example from the Opencv book I am trying to run for which i get the above error:
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <algorithm>
#include <iostream>
using namespace std;
struct AreaCmp
{
AreaCmp(const vector<float>& _areas) : areas(&_areas) {}
bool operator()(int a, int b) const {return (*areas)[a] > (*areas)[b];}
const vector<float>* areas;
};
int main(int argc, char* argv[])
{
cv::Mat img, img_edge,img_color;
img == cv :: imread(argv[1],cv::IMREAD_GRAYSCALE);
if(argc!=2 || (img.empty()))
{
cout<< "Check file and file format";
return -1;
}
cv::threshold(img,img_edge,128,255,cv::THRESH_BINARY);
cv::imshow("Image after threshold", img_edge);
vector<vector<cv::Point> >contours;
vector<cv::Vec4i>hierarchy;
cv::findContours(
img_edge,
contours,
hierarchy,
cv::RETR_LIST,
cv::CHAIN_APPROX_SIMPLE
);
cout<< "\n\nHit any key to ...
imread is imgcodecs lib imshow in highgui drawcontour in imgproc and you will need imgcore too
Now my system is windows But I think all libs start with libopencv_
Thanks, I added the code that gives the error, also tried and checked after adding imgcodec.hpp. Still the same error.
No it's a link error your code is correct. Try to download this compress folder. unzip it and in terminal cd infolderunncompress and ./buildmysource.sh and I hope it will be good
PS if you use #include "opencv2/opencv.hpp" you don''t other includes
I tried doing that but got "Permission denied " to sun the .sh file. Then I created a new directory with build and the CMakelists.txt and ran cmake and cmake build inside the build directory. But still the same error.
Have you got two opencv version? How do you install opencv?
I cloned from github and installed using cmake (using instructions on opencv.org). As I was getting this error, I tried to uninstall and reinstall, I think there might be two versions if i didnt uninstall properly.
You must have admin right to install opencv:
sudo make install
. If you cannot install opencv try opencv in static. Using windows you can use opencv without an installation process but I don't know linux