title: Compiling openCV 2.3.1 programs with MinGW gcc/g++ on Windows 7 64bit
body: <p>For a week I've been struggling with compiling openCV programs. I've tried everything I could possibly find on the internet. </p>
  
  <p>What I did is: I've downloaded <a href="http://sourceforge.net/projects/opencvlibrary/files/latest/download" rel="noreferrer">OpenCV-2.3.1-win-superpack.exe</a> and followed <a href="http://opencv.willowgarage.com/wiki/MinGW" rel="noreferrer">this official installation guide</a>.</p>
  
  <p>In the CMake (gui) my source was: D:\opencv and build destination was: C:\opencv. </p>
  
  <p>I've also added C:\opencv\install\bin;C:\opencv\bin to my system's PATH variable.</p>
  
  <p>What I want is to compile openCV programs on my Windows OS using MinGW's gcc/g++ compilers. </p>
  
  <p>I've tried various gcc/g++ parameters that I've found on the internet and days playing with the -I and -L options the compiler can never find the openCV functions or structures. </p>
  
  <p>What I am trying to compile:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  #include &lt;cv.h&gt;
  #include &lt;highgui.h&gt;
  
  int main(int argc, char *argv[])
  {
    // Nothing but create a window
    cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
    cvMoveWindow("mainWin", 100, 100);
    cvWaitKey(0);
    return 0;
  }
  </code></pre>
  
  <p>Error:</p>
  
  <p><b>Input</b>:</p>
  
  <pre><code>gcc test.c -o test -I"C:\opencv\install\include" -I"C:\opencv\install\include\opencv" -L"C:\opencv\install\bin"
  </code></pre>
  
  <p><b>Output</b>:</p>
  
  <pre><code>...\ccK4MfHv.o:test.c:(.text+0xa0b): undefined reference to `cvFree_'
  </code></pre>
  
  <p>Or with g++:</p>
  
  <p><b>Input</b>:</p>
  
  <pre><code>g++ test.c -o test -I"C:\opencv\install\include" -I"C:\opencv\install\include\opencv" -L"C:\opencv\install\bin"
  </code></pre>
  
  <p><b>Output</b>:</p>
  
  <pre><code>...\ccXCTKa1.o:test.c:(.text+0x1e): undefined reference to `cvNamedWindow'
  </code></pre>
  
  <p>Side note: trying to compile in VS2005 I get the same error.</p>
  
  <p>Thank you for your time!</p>