title: Conflicting declaration when cross compiling with mingw-w64 on Linux
body: <p>I've been trying to figure out an issue I've been having with cross-compiling C++ code on Linux for Windows. The code I'm trying to compile is:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main(int argc, char** argv){
      std::cout&lt;&lt;"Hello World!\n";
      return 0;
  }
  </code></pre>
  
  <p>I'm trying to compile for a 64 bit windows installation, and so I run:</p>
  
  <pre><code>x86_64-w64-mingw32-g++ main.cpp
  </code></pre>
  
  <p>but it produces the following errors:</p>
  
  <pre><code>In file included from /usr/include/sched.h:34:0,
                   from /usr/include/pthread.h:23,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/x86_64-w64-mingw32/bits/gthr-default.h:35,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/x86_64-w64-mingw32/bits/gthr.h:148,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ext/atomicity.h:35,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/bits/ios_base.h:39,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ios:42,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ostream:38,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/iostream:39,
                   from main.cpp:1:
  /usr/include/time.h:75:18: error: conflicting declaration ‘typedef __time_t time_t’
   typedef __time_t time_t;
                    ^
  In file included from /usr/x86_64-w64-mingw32/include/stddef.h:7:0,
                   from /usr/lib/gcc/x86_64-w64-mingw32/4.9.2/include/stddef.h:1,
                   from /usr/include/wchar.h:51,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/cwchar:44,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/bits/postypes.h:40,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/iosfwd:40,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ios:38,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ostream:38,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/iostream:39,
                   from main.cpp:1:
  /usr/x86_64-w64-mingw32/include/crtdefs.h:138:20: note: previous declaration as ‘typedef __time64_t time_t’
   typedef __time64_t time_t;
                      ^
  In file included from /usr/x86_64-w64-mingw32/include/c++/4.9.2/cwctype:50:0,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/bits/locale_facets.h:39,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/bits/basic_ios.h:37,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ios:44,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ostream:38,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/iostream:39,
                   from main.cpp:1:
  /usr/include/wctype.h:52:27: error: conflicting declaration ‘typedef long unsigned int wctype_t’
   typedef unsigned long int wctype_t;
                             ^
  In file included from /usr/x86_64-w64-mingw32/include/stddef.h:7:0,
                   from /usr/lib/gcc/x86_64-w64-mingw32/4.9.2/include/stddef.h:1,
                   from /usr/include/wchar.h:51,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/cwchar:44,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/bits/postypes.h:40,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/iosfwd:40,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ios:38,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ostream:38,
                   from /usr/x86_64-w64-mingw32/include/c++/4.9.2/iostream:39,
                   from main.cpp:1:
  /usr/x86_64-w64-mingw32/include/crtdefs.h:107:24: note: previous declaration as ‘typedef short unsigned int wctype_t’
   typedef unsigned short wctype_t;
                          ^
  </code></pre>
  
  <p>The error line:</p>
  
  <pre><code>/usr/include/time.h:75:18: error: conflicting declaration ‘typedef __time_t time_t’
   typedef __time_t time_t;
  </code></pre>
  
  <p>suggests to me that mingw-w64 is using the linux libraries instead of the ones compiled for windows, but upon searching I cannot seem to figure out how to resolve this. I'm using Archlinux and the mingw-w64 package group from the official repository. I've tried reinstalling the mingw-w64 package group thinking that maybe the libraries were not compiled correctly but I'm still receiving the same errors.</p>
  
  <p>To be clear, I am able to compile this code with:</p>
  
  <pre><code>g++ main.cpp
  </code></pre>
  
  <p>Any help or anything to point me in the right direction will be greatly appreciated. Thank you.</p>