title: How to solve undefined reference cv:.... when compiling openCV application in Linux/Ubuntu?
body: <p>I managed to build OpenCV (version 4.0.0) in a local folder in a OSX environment following <a href="https://stackoverflow.com/questions/51651362/how-to-include-and-use-opencv-library-when-installed-locally">these steps</a>.</p>
  
  <p>I tried the same steps in Linux and Ubuntu and did </p>
  
  <pre><code>export LD_LIBRARY_PATH=../your/path/lib/:$LD_LIBRARY_PATH
  </code></pre>
  
  <p>Everything looks fine but when I try to compile a test project with the <code>Makefile</code> I posted in the question I get this errrors</p>
  
  <pre><code>/tmp/ccVvPXNi.o: In function `cv::String::~String()':
  test.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
  /tmp/ccVvPXNi.o: In function `cv::String::operator=(cv::String const&amp;)':
  test.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x28): undefined reference to `cv::String::deallocate()'
  collect2: error: ld returned 1 exit status
  Makefile:23: recipe for target 'test.o' failed
  make: *** [test.o] Error 1
  </code></pre>
  
  <p>and with the following <code>Makefile</code> I get much more undefined references:</p>
  
  <pre><code>CPP = g++
  
  # OpenCV trunk
  CPPFLAGS = -std=c++11  \
             `pkg-config --cflags --libs ../cmake_bin_dir/instDir/lib/pkgconfig/opencv.pc`
  
  # Opencv 2.4.8
  #CPPFLAGS = -L/home/krystof/libs/opencv-2.4.8/release/installed/libs \
         -I/home/krystof/libs/opencv-2.4.8/release/installed/include
  
  all: provaMat
  
  provaMat.o: provaMat.cpp
      $(CPP) $(CPPFLAGS) $^ -o $@
  </code></pre>
  
  <p>I get the following errors in this case:</p>
  
  <pre><code>/tmp/ccwJs00N.o: In function `main':
  provaMat.cpp:(.text+0x38): undefined reference to `cv::VideoCapture::VideoCapture(int)'
  provaMat.cpp:(.text+0x47): undefined reference to `cv::VideoCapture::isOpened() const'
  provaMat.cpp:(.text+0x91): undefined reference to `cv::namedWindow(cv::String const&amp;, int)'
  provaMat.cpp:(.text+0xb3): undefined reference to `cv::VideoCapture::operator&gt;&gt;(cv::Mat&amp;)'
  provaMat.cpp:(.text+0x118): undefined reference to `cv::cvtColor(cv::_InputArray const&amp;, cv::_OutputArray const&amp;, int, int)'
  provaMat.cpp:(.text+0x1c5): undefined reference to `cv::GaussianBlur(cv::_InputArray const&amp;, cv::_OutputArray const&amp;, cv::Size_&lt;int&gt;, double, double, int)'
  provaMat.cpp:(.text+0x245): undefined reference to `cv::Canny(cv::_InputArray const&amp;, cv::_OutputArray const&amp;, double, double, int, bool)'
  provaMat.cpp:(.text+0x2ab): undefined reference to `cv::imshow(cv::String const&amp;, cv::_InputArray const&amp;)'
  provaMat.cpp:(.text+0x2d3): undefined reference to `cv::waitKey(int)'
  provaMat.cpp:(.text+0x322): undefined reference to `cv::VideoCapture::~VideoCapture()'
  provaMat.cpp:(.text+0x41b): undefined reference to `cv::VideoCapture::~VideoCapture()'
  /tmp/ccwJs00N.o: In function `cv::String::String(char const*)':
  provaMat.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x54): undefined reference to `cv::String::allocate(unsigned long)'
  /tmp/ccwJs00N.o: In function `cv::String::~String()':
  provaMat.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
  /tmp/ccwJs00N.o: In function `cv::String::operator=(cv::String const&amp;)':
  provaMat.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x28): undefined reference to `cv::String::deallocate()'
  /tmp/ccwJs00N.o: In function `cv::Mat::~Mat()':
  provaMat.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
  /tmp/ccwJs00N.o: In function `cv::Mat::release()':
  provaMat.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
  collect2: error: ld returned 1 exit status
  Makefile:14: recipe for target 'provaMat.o' failed
  make: *** [provaMat.o] Error 1
  </code></pre>
  
  <p>What step am I missing? Does anyone have a suggestion?</p>
  
  <p>EDIT:
  The result of <code>pkg-config --cflags --libs ../cmake_bin_dir/instDir/lib/pkgconfig/opencv.pc</code> is </p>
  
  <pre><code>-I/root/openCV4/cmake_bin_dir/instDir/include/opencv -I/root/openCV4/cmake_bin_dir/instDir/include -L/root/openCV4/cmake_bin_dir/instDir/lib -lopencv_dnn -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core
  </code></pre>