title: How do I get pthreads to work in Windows?
body: <p>I was running into errors such as those mentioned bellow when trying to compile code containing pthreads</p>
  
  <pre><code>warning: return type defaults to 'int' [-Wreturn-type]|
  |In function 'print_message_function':|
  warning: control reaches end of non-void function [-Wreturn-type]|
  | undefined reference to `_imp__pthread_create'|
  | undefined reference to `_imp__pthread_create'|
  | undefined reference to `_imp__pthread_join'|
  | undefined reference to `_imp__pthread_join'|
  </code></pre>
  
  <p>I'm running GCC on Windows 7 but I have mingw installed. I'm using the IDE Code::Blocks and select "compile current file". Here is a screen shot of the linker settings, I'm at a loss here</p>
  
  <p><img src="https://i.stack.imgur.com/Cp1m2.png" alt="codeblocks linker"></p>
  
  <p><strong>UPDATE</strong>: I added <code>-pthread</code> to the "Other linker options" and it works better. There still are problems. When I compile it says </p>
  
  <pre><code>|In function 'print_message_function':|
  warning: control reaches end of non-void function [-Wreturn-type]|
  </code></pre>
  
  <p>and when I go to run it CodeBlocks says "it appears the program has not been built yet" and when I click on "build" I am shown this error</p>
  
  <pre><code>mingw32-g++.exe  -o "SimpleExample.exe" "SimpleExample.o"  -static-libgcc -static-libstdc++ -pthread  
  mingw32-g++.exe: error: unrecognized option '-pthread'
  Process terminated with status 1 (0 minutes, 0 seconds)
  0 errors, 1 warnings (0 minutes, 0 seconds)
  </code></pre>
  
  <p>How do I fix this? I want to build/test on Windows but have the program run on a Unix environment. What is the difference between compile and build in an IDE?</p>