Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.

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 tocv::imread(cv::String const&, int)' boxdetect.cpp:(.text+0xb1): undefined reference to cv::operator==(cv::Mat const&, cv::Mat const&)' boxdetect.cpp:(.text+0x198): undefined reference tocv::threshold(cv::_InputArray const&, cv::_OutputArray const&, double, double, int)' boxdetect.cpp:(.text+0x1fc): undefined reference to cv::imshow(cv::String const&, cv::_InputArray const&)' boxdetect.cpp:(.text+0x2c4): undefined reference tocv::findContours(cv::_InputOutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, int, int, cv::Point_<int>)' boxdetect.cpp:(.text+0x49b): undefined reference to cv::contourArea(cv::_InputArray const&, bool)' boxdetect.cpp:(.text+0x5af): undefined reference tocv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)' boxdetect.cpp:(.text+0x693): undefined reference to cv::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 tocv::imshow(cv::String const&, cv::_InputArray const&)' boxdetect.cpp:(.text+0x7e7): undefined reference to cv::waitKey(int)' /tmp/ccP0Zecd.o: In functioncv::String::String(char const*)': boxdetect.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x54): undefined reference to cv::String::allocate(unsigned long)' /tmp/ccP0Zecd.o: In functioncv::String::~String()': boxdetect.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to cv::String::deallocate()' /tmp/ccP0Zecd.o: In functioncv::String::operator=(cv::String const&)': boxdetect.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x28): undefined reference to cv::String::deallocate()' /tmp/ccP0Zecd.o: In functioncv::Mat::~Mat()': boxdetect.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to cv::fastFree(void*)' /tmp/ccP0Zecd.o: In functioncv::Mat::release()': boxdetect.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()' collect2: error: ld returned 1 exit status

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 tocv::imread(cv::String const&, int)' boxdetect.cpp:(.text+0xb1): undefined reference to cv::operator==(cv::Mat const&, cv::Mat const&)' boxdetect.cpp:(.text+0x198): undefined reference tocv::threshold(cv::_InputArray const&, cv::_OutputArray const&, double, double, int)' boxdetect.cpp:(.text+0x1fc): undefined reference to cv::imshow(cv::String const&, cv::_InputArray const&)' boxdetect.cpp:(.text+0x2c4): undefined reference tocv::findContours(cv::_InputOutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, int, int, cv::Point_<int>)' boxdetect.cpp:(.text+0x49b): undefined reference to cv::contourArea(cv::_InputArray const&, bool)' boxdetect.cpp:(.text+0x5af): undefined reference tocv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)' boxdetect.cpp:(.text+0x693): undefined reference to cv::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 tocv::imshow(cv::String const&, cv::_InputArray const&)' boxdetect.cpp:(.text+0x7e7): undefined reference to cv::waitKey(int)' /tmp/ccP0Zecd.o: In functioncv::String::String(char const*)': boxdetect.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x54): undefined reference to cv::String::allocate(unsigned long)' /tmp/ccP0Zecd.o: In functioncv::String::~String()': boxdetect.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to cv::String::deallocate()' /tmp/ccP0Zecd.o: In functioncv::String::operator=(cv::String const&)': boxdetect.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x28): undefined reference to cv::String::deallocate()' /tmp/ccP0Zecd.o: In functioncv::Mat::~Mat()': boxdetect.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to cv::fastFree(void*)' /tmp/ccP0Zecd.o: In functioncv::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 draw the next contour, ESC to Quit\n\n";
cout<< "Total Contours Detected:" << contours.size() << endl;

vector<int> sortIdx(contours.size());
vector<float> areas(contours.size());
for (int n=0; n<(int)contours.size();n++)
{
    sortIdx[n]=n;
    areas[n] = contourArea(contours[n],false);
}

std::sort (sortIdx.begin(), sortIdx.end(), AreaCmp(areas));

for (int n=0; n<(int)sortIdx.size(); n++)
{
    int idx = sortIdx[n];
    cv::cvtColor(img,img_color,cv::COLOR_GRAY2BGR);
    cv::drawContours(
        img_color,contours,idx, cv::Scalar(0,0,255), 2,8, hierarchy,0
    );

    cout<< "Contour #" << idx << ":area=" << areas[idx] << ", nvertices=" << contours[idx].size() << endl;
    cv::imshow(argv[0], img_color);
    int k;
    if((k= cv::waitKey()&255) == 27)
        break;

}
cout<< "Finished all contours\n";
return 0;
}