title: How to link to opencv 3.0 when compiled from source on Ubuntu 14.04?
body: <p>I'm trying to compile and link the following opencv program that I found online:</p>
  
  <p>main.cpp:</p>
  
  <pre><code>#include &lt;opencv2/highgui.hpp&gt;
  #include &lt;opencv2/imgproc.hpp&gt;
  #include &lt;opencv2/videoio.hpp&gt;
  
  #include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  
  using namespace std;
  using namespace cv;
  int main( int argc, const char** argv )
  {
          VideoCapture capture(0);
  
          while(capture.isOpened() )
          {
                  Mat frame;
                  if (! capture.read(frame))
                          continue;
  
                  imshow("lalala", frame);
                  if(waitKey(10) == 27)
                          break;
          }
  
  
  
          return 0;
  }
  </code></pre>
  
  <p>My filestructure is as follows:</p>
  
  <p>~/dev/opencv-1</p>
  
  <p>~/dev/opencv-example</p>
  
  <p>The opencv-1 is a git clone of: <a href="https://github.com/Itseez/opencv" rel="nofollow">https://github.com/Itseez/opencv</a> </p>
  
  <p>I followed the instructions located at: <a href="http://docs.opencv.org/trunk/doc/tutorials/introduction/linux_install/linux_install.html" rel="nofollow">http://docs.opencv.org/trunk/doc/tutorials/introduction/linux_install/linux_install.html</a></p>
  
  <p>My goal was to debug into the opencv code, so I used the CMAKE_BUILD_TYPE=Debug</p>
  
  <p>I was able to get the opencv code to compile sucessfuly. I wrote the following makefile to compile this sample:</p>
  
  <pre><code>INCPATH =-I../opencv-1/modules/objdetect/include \
     -I../opencv-1/modules/highgui/include \
     -I../opencv-1/modules/imgproc/include \
     -I../opencv-1/modules/core/include \
     -I../opencv-1/modules/imgcodecs/include \
     -I../opencv-1/modules/videoio/include \
  
  LIBPATH =-L../opencv-1/debug/lib
  
  LIBS =-lopencv_core -lopencv_videoio -lopencv_highgui -lopencv_imgproc -lopencv_video -lopencv_objdetect
  
  %:%.cpp
          g++ $(INCPATH) $(LIBS) $(LIBPATH) $^ -o $@
  </code></pre>
  
  <p>To compile I ran: make main</p>
  
  <p>When this happens, I get the following linking errors:</p>
  
  <pre><code>g++ -I../opencv-1/modules/objdetect/include -I../opencv-1/modules/highgui/include -I../opencv-1/module                                                              s/imgproc/include -I../opencv-1/modules/core/include -I../opencv-1/modules/imgcodecs/include -I../open                                                              cv-1/modules/videoio/include  -lopencv_core -lopencv_videoio -lopencv_highgui -lopencv_imgproc -lopenc                                                              v_video -lopencv_objdetect -L../opencv-1/debug/lib main.cpp -o main
  /tmp/cc0PMDdW.o: In function `main':
  main.cpp:(.text+0x29): undefined reference to `cv::VideoCapture::VideoCapture(int)'
  main.cpp:(.text+0x69): undefined reference to `cv::VideoCapture::read(cv::_OutputArray const&amp;)'
  main.cpp:(.text+0xce): undefined reference to `cv::imshow(cv::String const&amp;, cv::_InputArray const&amp;)'
  main.cpp:(.text+0xf6): undefined reference to `cv::waitKey(int)'
  main.cpp:(.text+0x131): undefined reference to `cv::VideoCapture::isOpened() const'
  main.cpp:(.text+0x14d): undefined reference to `cv::VideoCapture::~VideoCapture()'
  main.cpp:(.text+0x1b0): undefined reference to `cv::VideoCapture::~VideoCapture()'
  /tmp/cc0PMDdW.o: In function `cv::String::String(char const*)':
  main.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4f): undefined reference to `cv::String::al                                                              locate(unsigned long)'
  /tmp/cc0PMDdW.o: In function `cv::String::~String()':
  main.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallo                                                              cate()'
  /tmp/cc0PMDdW.o: In function `cv::_InputArray::_InputArray()':
  main.cpp:(.text._ZN2cv11_InputArrayC2Ev[_ZN2cv11_InputArrayC5Ev]+0x13): undefined reference to `vtable                                                               for cv::_InputArray'
  /tmp/cc0PMDdW.o: In function `cv::_InputArray::_InputArray(cv::Mat const&amp;)':
  main.cpp:(.text._ZN2cv11_InputArrayC2ERKNS_3MatE[_ZN2cv11_InputArrayC5ERKNS_3MatE]+0x17): undefined re                                                              ference to `vtable for cv::_InputArray'
  /tmp/cc0PMDdW.o: In function `cv::_InputArray::~_InputArray()':
  main.cpp:(.text._ZN2cv11_InputArrayD2Ev[_ZN2cv11_InputArrayD5Ev]+0x13): undefined reference to `vtable                                                               for cv::_InputArray'
  /tmp/cc0PMDdW.o: In function `cv::_OutputArray::_OutputArray(cv::Mat&amp;)':
  main.cpp:(.text._ZN2cv12_OutputArrayC2ERNS_3MatE[_ZN2cv12_OutputArrayC5ERNS_3MatE]+0x23): undefined re                                                              ference to `vtable for cv::_OutputArray'
  /tmp/cc0PMDdW.o: In function `cv::_OutputArray::~_OutputArray()':
  main.cpp:(.text._ZN2cv12_OutputArrayD2Ev[_ZN2cv12_OutputArrayD5Ev]+0x13): undefined reference to `vtab                                                              le for cv::_OutputArray'
  /tmp/cc0PMDdW.o: In function `cv::Mat::~Mat()':
  main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
  /tmp/cc0PMDdW.o: In function `cv::Mat::release()':
  main.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::dea                                                              llocate()'
  collect2: error: ld returned 1 exit status
  make: *** [main] Error 1
  </code></pre>
  
  <p>I'm not sure what I'm missing. I've included all of the libraries that this simple program should need to compile. I've searched online for similar errors and all of the answers I've seen suggest adding the libraries that are already in my makefile. </p>