How can I correctly link OpenCV libraries to Eclipse on Windows?
<p>For the last couple of hours I have been trying to get a basic OpenCV program to work in my Eclipse Mars IDE. The program consists of the following main.cpp:</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], CV_LOAD_IMAGE_COLOR);   // 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", 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>What I have done up till now:</p>

<ol>
<li>Installed MinGW (in E:\NVPACK\MinGW) and added its bin file path to my Environmental Variables.</li>
<li><p>Installed OpenCV 2.4.12 at E:\opencv. Inside the installed folder are the "build" and "sources" folder. </p></li>
<li><p>Made a new Eclipse C++ project with the MinGW GCC Toolchain. </p></li>
<li><p>Inside the Tool Settings (Project Properties --> C/C++ Build --> Settings) I included the OpenCV library in the GCC C++ Compiler as "E:\opencv\build\include"</p></li>
<li><p>Inside the Tool Settings I added in the MinGW C++ Linker all the libraries (i.e. opencv_core2412, opencv_highgui2412, opencv_imgproc2412) and set the Library search path to "E:\opencv\build\x86\vc12\lib"</p></li>
<li><p>Set my Binary parser to PE Windows Parser.</p></li>
</ol>

<p>Building the project all the OpenCV functions get undefined references errors, such as:</p>

<pre><code>undefined reference to `cv::imread(std::string const&amp;, int)'    main.cpp    line 17 C/C++ Problem
undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&amp;)'   main.cpp    line 26 C/C++ Problem
</code></pre>

<p>Weird enough, declaring Mat image does not give an error and holding my mouse over it correctly displays the OpenCV's Mat documentation.</p>

<p>Googling the problem I found that for some reason I might need to use CMake to build my own library files (the ones used in step 5). So after installing CMake gui, I used E:\opencv\sources as the source directory and made a new directory E:\opencv\MinGW as my build directory. I used "Eclipse CDT4 -MinGW Makefiles" generator to Configure the files. After pressing Configure, I will receive the following error for my g++ compiler (a similar one for my gcc compiler):</p>

<pre><code>CMake Error at CMakeLists.txt:71 (project):
The CMAKE_CXX_COMPILER:

E:/NVPACK/MinGW/bin/mingw32-g++

is not a full path to an existing compiler tool.

Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
</code></pre>

<p>The compilers are however identified: "The CXX compiler identification is GNU 4.8.1" and "The C compiler identification is GNU 4.8.1"</p>

<p>Any help on how to correctly set up the OpenCV 2.4.12 libraries in Eclipse Mars on Windows 7 would be very much appreciated!</p>