title: Cannot get OpenCV to compile because of undefined references?
body: <p>The code is simple and is essentially straight from <a href="http://docs.opencv.org/doc/tutorials/introduction/load_save_image/load_save_image.html#load-save-image">this</a> tutorial. I am running Arch Linux and have the OpenCV library stored at <code>/usr/include/</code>. I have also checked to ensure that <code>/usr/include</code> is in my PATH. </p>
  
  <pre><code>#include &lt;opencv/cv.h&gt;
  #include &lt;opencv/highgui.h&gt;
  #include &lt;iostream&gt;
  
  using namespace cv; 
  
  int main(int argc, char** argv){
      Mat image;
      Mat grayImage; 
  
      if(!argv[1]){
          std::cerr &lt;&lt; "No image data!" &lt;&lt; std::endl;
          return -1; 
      }
  
      image = imread(argv[1], 1);
      cvtColor(image, grayImage, CV_BGR2GRAY);
      imwrite("Gray_Image.jpg", grayImage);
  
      namedWindow(argv[1], CV_WINDOW_AUTOSIZE);
      namedWindow("Gray Image", CV_WINDOW_AUTOSIZE);
  
      imshow(argv[1], image);
      imshow("Gray Image", grayImage);
  
      waitKey(0);
      return 0;
  }
  </code></pre>
  
  <p>The compiler process successfully finds and include these header files, but I still get undefined reference errors at compile-time. If you look into the header files I included they further include other files in <code>/usr/include/opencv2</code>. I have checked and such header files do exist. </p>
  
  <p>Any ideas? </p>
  
  <pre><code>/tmp/ccudBcqD.o: In function `main':
  test.cpp:(.text+0xc0): undefined reference to `cv::imread(std::string const&amp;, int)'
  test.cpp:(.text+0x11f): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&amp;)'
  test.cpp:(.text+0x138): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&amp;)'
  test.cpp:(.text+0x158): undefined reference to `cv::cvtColor(cv::_InputArray const&amp;, cv::_OutputArray const&amp;, int, int)'
  test.cpp:(.text+0x180): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&amp;)'
  test.cpp:(.text+0x1ca): undefined reference to `cv::imwrite(std::string const&amp;, cv::_InputArray const&amp;, std::vector&lt;int, std::allocator&lt;int&gt; &gt; const&amp;)'
  test.cpp:(.text+0x241): undefined reference to `cv::namedWindow(std::string const&amp;, int)'
  test.cpp:(.text+0x291): undefined reference to `cv::namedWindow(std::string const&amp;, int)'
  test.cpp:(.text+0x2bf): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&amp;)'
  test.cpp:(.text+0x2ff): undefined reference to `cv::imshow(std::string const&amp;, cv::_InputArray const&amp;)'
  test.cpp:(.text+0x32d): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&amp;)'
  test.cpp:(.text+0x361): undefined reference to `cv::imshow(std::string const&amp;, cv::_InputArray const&amp;)'
  test.cpp:(.text+0x383): undefined reference to `cv::waitKey(int)'
  /tmp/ccudBcqD.o: In function `cv::Mat::~Mat()':
  test.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
  /tmp/ccudBcqD.o: In function `cv::Mat::operator=(cv::Mat const&amp;)':
  test.cpp:(.text._ZN2cv3MataSERKS0_[_ZN2cv3MataSERKS0_]+0x111): undefined reference to `cv::Mat::copySize(cv::Mat const&amp;)'
  /tmp/ccudBcqD.o: In function `cv::Mat::release()':
  test.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47): undefined reference to `cv::Mat::deallocate()'
  collect2: error: ld returned 1 exit status
  [Finished in 1.1s with exit code 1]
  [shell_cmd: g++ "/home/branden/Desktop/OpenCV/test.cpp" -o "/home/branden/Desktop/OpenCV/test"]
  [dir: /home/branden/Desktop/OpenCV]
  [path: /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/vendor_perl:/usr/bin/core_perl]
  </code></pre>