Skip to content
Advertisement

OpenCV 3.1 Upgrade Leads to Linker Errors on Linux

I’ve recently upgraded from OpenCV 2.4.11 to OpenCV 3.1 by following this guide. This sudo make install seems to have worked successfully and when I run pkg-config –modversion opencv, I get the appropriate version (3.1.0).

But for some reason, I am now running into linker errors, and even simple programs are unable to compile, for example:

#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, char* argv[])
{
   Mat im1 = imread(argv[1]);
   return 0;
}

returns the errors:

main.cpp:-1: error: undefined reference to cv::imread(cv::String const&, int)

main.cpp:-1: error: undefined reference to `cv::String::allocate(unsigned long)’

main.cpp:-1: error: undefined reference to `cv::String::deallocate()’

:-1: error: collect2: error: ld returned 1 exit status

Could this be due to conflicts with the previous installation? Before I go through and start manually deleting files in /usr/local/ [lib | include | bin], I thought I’d ask here first. Any suggestions?

Advertisement

Answer

I went ahead and took the nuclear option (sudo rm followed by sudo make install), and everything compiles now. I’m not proud of this, nor do I necessarily advocate it, but if anyone else reaches this point of desperation, you may find this kill log helpful:

sudo rm -r /usr/share/opencv
sudo rm -r /usr/share/OpenCV/
sudo rm -r /usr/local/include/opencv
sudo rm -r /usr/local/bin/opencv*
sudo rm -r /usr/local/share/OpenCV/
sudo rm -r /usr/local/lib/libopencv_*
sudo rm    /usr/local/lib/pkgconfig/opencv.pc
sudo rm    /usr/local/lib/python2.7/dist-packages/cv2.so
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement