title: "Function not declared in this scope" Error in compiling openCV code
body: <p>I'm trying to write some code which uses openCV functions. I started by taking some of the example code available in the documentation:</p>
  
  <pre><code>#include &lt;opencv2/core/core.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  #include &lt;iostream&gt;
  
  using namespace cv;
  using namespace std;
  
  int main( int argc, char** argv )
  {
      if( argc != 2)
      {
       cout &lt;&lt;" Usage: display_image ImageToLoadAndDisplay" &lt;&lt; endl;
       return -1;
      }
  
      Mat image;
      image = imread(argv[1]);   // Read the file
  
      if(! image.data )                              // Check for invalid input
      {
          cout &lt;&lt;  "Could not open or find the image" &lt;&lt; std::endl ;
          return -1;
      }
  
      namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
      imshow( "Display window", image );                   // Show our image inside it.
  
      waitKey(0);                                          // Wait for a keystroke in the window
      return 0;
  }
  </code></pre>
  
  <p>When I try to build it in Eclipse-CDT, I get this:</p>
  
  <pre><code>**** Build of configuration Debug for project openCV1 ****
  
  make all 
  Building target: openCV1
  Invoking: Cross G++ Linker
  g++ -L/usr/local/lib -o "openCV1"  ./src/displayImage.o   
  ./src/displayImage.o: In function `main':
  /home/jackstinger/workspace1/openCV1/Debug/../src/displayImage.cpp:25: undefined reference to `cv::imread(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, int)'
  /home/jackstinger/workspace1/openCV1/Debug/../src/displayImage.cpp:33: undefined reference to `cv::namedWindow(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, int)'
  /home/jackstinger/workspace1/openCV1/Debug/../src/displayImage.cpp:34: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&amp;)'
  /home/jackstinger/workspace1/openCV1/Debug/../src/displayImage.cpp:34: undefined reference to `cv::imshow(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, cv::_InputArray const&amp;)'
  /home/jackstinger/workspace1/openCV1/Debug/../src/displayImage.cpp:36: undefined reference to `cv::waitKey(int)'
  ./src/displayImage.o: In function `~Mat':
  /usr/local/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
  ./src/displayImage.o: In function `cv::Mat::operator=(cv::Mat const&amp;)':
  /usr/local/include/opencv2/core/mat.hpp:298: undefined reference to `cv::Mat::copySize(cv::Mat const&amp;)'
  ./src/displayImage.o: In function `cv::Mat::release()':
  /usr/local/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
  collect2: ld returned 1 exit status
  make: *** [openCV1] Error 1
  
  **** Build Finished ****
  </code></pre>
  
  <p>The same code, when I build with g++ (<code>g++ -o displayImageInput displayImageInput.cpp</code>pkg-config opencv --cflags --libs) works.</p>
  
  <p>I then changed the code to make the image greyscale,</p>
  
  <pre><code>#include &lt;opencv2/core/core.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  #include &lt;iostream&gt;
  
  using namespace cv;
  using namespace std;
  
  int main( int argc, char** argv )
  {
      if( argc != 2)
      {
       cout &lt;&lt;" Usage: display_image ImageToLoadAndDisplay" &lt;&lt; endl;
       return -1;
      }
  
      Mat image;
      image = imread(argv[1]);   // Read the file
  
      if(! image.data )                              // Check for invalid input
      {
          cout &lt;&lt;  "Could not open or find the image" &lt;&lt; std::endl ;
          return -1;
      }
  
      Mat grey;
      cvtColor(image, grey, CV_BGR2GRAY);
  
      namedWindow("image", CV_WINDOW_AUTOSIZE);
      imshow("image", grey);
      waitKey();                                         // Wait for a keystroke in the window
      return 0;
  }
  </code></pre>
  
  <p>It gave the following error when building with g++:</p>
  
  <pre><code>dispImgSobel.cpp: In function ‘int main(int, char**)’:
  dispImgSobel.cpp:34:27: error: ‘CV_BGR2GRAY’ was not declared in this scope
  dispImgSobel.cpp:34:38: error: ‘cvtColor’ was not declared in this scope
  </code></pre>
  
  <p>I need help with two things, How to get it working in Eclipse, and second, how to resolve this scope error, for this and future use cases.</p>