title: Using openmp on windows with mingw. Cannot find -lpthread
body: <p>I have a CMake project which is using OpenMP and works on linux. 
  When I went to compile it on my windows machine it looked like CMake was having trouble finding the openmp flags for mingw's gcc. </p>
  
  <p>I decided to try a smaller test case and just compile main_openmp.c</p>
  
  <pre><code>#include &lt;omp.h&gt;
  #include &lt;stdio.h&gt;
  int main(int argc, char* argv[]) {
      int id;
      #pragma omp parallel private(id)
          {
          id = omp_get_thread_num();
          printf("%d: Hello World!\n", id);
          }
      return 0;
  }
  </code></pre>
  
  <p>Then when I try to compile </p>
  
  <pre><code>gcc -o OpenMPTest2 main_testomp.c -fopenmp
  </code></pre>
  
  <p>I get </p>
  
  <pre><code>&gt;&gt;&gt; gcc -o OpenMPTest2 main_testomp.c -fopenmp
  c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lpthread
  collect2.exe: error: ld returned 1 exit status
  </code></pre>
  
  <p>I attempted to find the solution online and tried variants of -lgomp, -lpthreadgc2, and -lpthreadvc2, with no improvement. </p>
  
  <p>I searched my C:\MinGw directory recursively for any filenames containing lpthread and got this: </p>
  
  <pre><code>C:\MinGW\bin\pthreadgc2.dll
  C:\MinGW\bin\pthreadgce2.dll
  C:\MinGW\var\cache\mingw-get\packages\pthreads-w32-2.9.1-1-mingw32-dll.tar.lzma
  C:\MinGW\var\lib\mingw-get\data\mingw32-pthreads-w32.xml
  </code></pre>
  
  <p>I'm not sure if I'm missing a flag, or a package, or what I'm doing wrong. For good measure here is the output of gcc -v</p>
  
  <pre><code>Using built-in specs.
  COLLECT_GCC=gcc
  COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe
  Target: mingw32
  Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=mingw32 --without-pic
   --enable-shared --enable-static --with-gnu-ld --enable-lto --enable-libssp --disable-multilib --ena
  ble-languages=c,c++,fortran,objc,obj-c++,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32
  -registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gm
  p-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --with-mpfr= --with-sy
  stem-zlib --with-gnu-as --enable-decimal-float=yes --enable-libgomp --enable-threads --with-libiconv
  -prefix=/mingw32 --with-libintl-prefix=/mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIM
  E_T
  Thread model: win32
  gcc version 4.8.1 (GCC)
  </code></pre>
  
  <p>Any idea what's wrong? </p>