I am trying to run an open-source program that uses, among other things, OpenCV. I initially ran into undefined reference
errors which changed into
Package opencv was not found in the pkg-config search path
errors which then returned to undefined reference
problems. The details are in the background. The compiling command and error message are included as well.
- My initial error was a long list of 'undefined reference' errors. I could not resolve it, but noticed on, this StackOverflow question that if I tried it on Ubuntu instead of Windows, I could try adding
pkg-config --cflags --libs opencv
. - Then my compilation error changed from
undefined reference to ...
toPackage opencv was not found in the pkg-config search path
etc.- The accepted solution (StackOverflow question ) seemed to be to create a file called opencv.pc, copy it to
/usr/local/lib/pkgconfig
, to include it in some given lines, then add some other given lines to bashrc. However, when I created theopencv.pc
file, it just made a blank text file calledopencv.pc
instead of an actual.pc
file. Furthermore, the directory/usr/local/lib/pkgconfig
doesn't exist on my computer even thoughpkg-config
is definitely installed.
- The accepted solution (StackOverflow question ) seemed to be to create a file called opencv.pc, copy it to
I could not get this solution to work, so I kept searching and thought that perhaps part of the problem was that instead of installing OpenCV from the terminal, I had copied it from my Windows computer with a USB key. So I tried installing it with the terminal using this line:
sudo apt-get install libopencv-dev
. Now my error is once againundefined references
despite the fact that I still have
pkg-config ...
in the compiling command. Note that it's not just OpenCV that has undefined references but also files particular to the open-source program I am trying to run (it's called 'PuRe', an eye-gaze tracking algorithm).
g++ -I /home/binny/Desktop/opencv/build/include/opencv2/imgcodecs -std=c++11 -I /home/binny/Desktop/example/ -I /home/binny/Desktop/opencv/build/include/ -I /home/binny/Desktop/winrt_x86_msvc2017/include/ -I /home/binny/Desktop/winrt_x86_msvc2017/include/QtCore /home/binny/Desktop/example/main.cpp `pkg-config --cflags --libs opencv
/tmp/ccLpYSrK.o: In function `main':
main.cpp:(.text+0x49): undefined reference to `cv::imread(cv::String const&, int)'
main.cpp:(.text+0x218): undefined reference to `PuRe::PuRe()'
main.cpp:(.text+0x238): undefined reference to `PuRe::run(cv::Mat const&, Pupil&)'
main.cpp:(.text+0x2cd): undefined reference to `cv::ellipse(cv::_InputOutputArray const&, cv::RotatedRect const&, cv::Scalar_<double> const&, int, int)'
main.cpp:(.text+0x322): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
main.cpp:(.text+0x35e): undefined reference to `PuRe::~PuRe()'
main.cpp:(.text+0x484): undefined reference to `PuRe::~PuRe()'
/tmp/ccLpYSrK.o: In function `cv::String::String(char const*)':
main.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x54): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/ccLpYSrK.o: In function `cv::String::~String()':
main.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/ccLpYSrK.o: In function `cv::String::operator=(cv::String const&)':
main.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x28): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status