title: Problems compiling C++ programs with wineg++/winelib
body: <p>I am having trouble compiling C++ programs with <code>wineg++</code>. To illustrate my problem, I have written two test programs.</p>
  
  <h3>msgbox.cpp</h3>
  
  <pre><code>#include &lt;algorithm&gt;
  #include &lt;iterator&gt;
  #include &lt;cstdio&gt;
  
  #include &lt;windows.h&gt;
  
  int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
  {
      char buf[30], *pos = buf;
      int xs[] = {1,3,2,4,3,5,4,6,5,7,6,8,7,9};
  
      std::sort( std::begin(xs), std::end(xs) );
      for (int x : xs) {
          pos += std::sprintf(pos, "%d ", x);
      }
  
      MessageBox(0, buf, "Hello", 0);
      return 0;
  }
  </code></pre>
  
  <h3>frame.cpp</h3>
  
  <pre><code>#include "../win32xx/include/wxx_wincore.h"
  #include "../win32xx/include/wxx_frame.h"
  
  int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
  {
      CWinApp winApp;
      CFrame frame;
      CWnd view;
      frame.SetView(view);
      frame.Create();
      winApp.Run();
  }
  </code></pre>
  
  <p>The second program uses the <a href="http://win32-framework.sourceforge.net/" rel="nofollow noreferrer">Win32++</a> library, which I can't recommend enough.</p>
  
  <p>Both programs compile and run just fine using a cross-compiler:</p>
  
  <pre><code>okuu% x86_64-w64-mingw32-g++ msgbox.cpp -o msgbox.exe
  okuu% wine ./msgbox.exe
  okuu% x86_64-w64-mingw32-g++ frame.cpp -o frame.exe -lgdi32 -lcomctl32 -static
  okuu% wine ./frame.exe
  okuu% rm *exe*
  </code></pre>
  
  <p>But I want to use <code>winelib</code> so that I can use both the Windows API and Unix libraries. This is what I tried first:</p>
  
  <pre><code>okuu% wineg++ msgbox.cpp -o msgbox.exe
  okuu% ./msgbox.exe
  okuu% wineg++ frame.cpp -o frame.exe -mwindows
  In file included from ../win32xx/include/wxx_appcore.h:57:0,
                   from ../win32xx/include/wxx_wincore.h:96,
                   from frame.cpp:1:
  ../win32xx/include/wxx_appcore0.h:120:12: fatal error: process.h: No such file or directory
     #include &lt;process.h&gt;
              ^~~~~~~~~~~
  compilation terminated.
  winegcc: g++ failed
  </code></pre>
  
  <p>Then I read <code>wineg++</code>'s man page, which says:</p>
  
  <blockquote>
    <p><strong>-mno-cygwin</strong><br>
    Use Wine implementation of MSVCRT, instead of linking against the host system libc. This is necessary for the vast majority of Win32 applications, as they typically depend on various features of MSVCRT. This switch is also used by the MinGW compiler to link against MSVCRT on Windows, instead of linking against Cygwin libc. Sharing the syntax with MinGW makes it very easy to write  Makefiles that work under Wine, MinGW+MSYS, or MinGW+Cygwin.</p>
  </blockquote>
  
  <p>So I tried again with <code>-mno-cygwin</code>, and got a 2000-line error message that begins with:</p>
  
  <pre><code>okuu% wineg++ frame.cpp -o frame.exe -mwindows -mno-cygwin
  In file included from /usr/include/c++/7.2.1/cstdlib:75:0,
                   from /usr/include/c++/7.2.1/bits/stl_algo.h:59,
                   from /usr/include/c++/7.2.1/algorithm:62,
                   from ../win32xx/include/wxx_appcore0.h:110,
                   from ../win32xx/include/wxx_appcore.h:57,
                   from ../win32xx/include/wxx_wincore.h:96,
                   from frame.cpp:1:
  /usr/include/stdlib.h:310:5: error: ‘int32_t’ does not name a type; did you mean ‘wint_t’?
       int32_t *fptr;  /* Front pointer.  */
       ^~~~~~~
       wint_t
  /usr/include/stdlib.h:311:5: error: ‘int32_t’ does not name a type; did you mean ‘wint_t’?
       int32_t *rptr;  /* Rear pointer.  */
       ^~~~~~~
       wint_t
  /usr/include/stdlib.h:312:5: error: ‘int32_t’ does not name a type; did you mean ‘wint_t’?
       int32_t *state;  /* Array of state values.  */
       ^~~~~~~
       wint_t
  /usr/include/stdlib.h:316:5: error: ‘int32_t’ does not name a type; did you mean ‘wint_t’?
       int32_t *end_ptr;  /* Pointer behind state table.  */
       ^~~~~~~
       wint_t
  /usr/include/stdlib.h:320:8: error: ‘int32_t’ has not been declared
          int32_t *__restrict __result) __THROW __nonnull ((1, 2));
          ^~~~~~~
  </code></pre>
  
  <p>So it seems C99's fixed-size integer types are not available. That seems easy enough to solve:</p>
  
  <h3>frame.cpp</h3>
  
  <pre><code>#include &lt;stdint.h&gt;
  #include "../win32xx/include/wxx_wincore.h"
  #include "../win32xx/include/wxx_frame.h"
  // etc. etc. etc.
  </code></pre>
  
  <p>And I tried again, but got a different 2000-line error message that begins with:</p>
  
  <pre><code>okuu% wineg++ frame.cpp -o frame.exe -mwindows -mno-cygwin
  In file included from /usr/include/c++/7.2.1/cwchar:44:0,
                   from /usr/include/c++/7.2.1/bits/postypes.h:40,
                   from /usr/include/c++/7.2.1/bits/char_traits.h:40,
                   from /usr/include/c++/7.2.1/string:40,
                   from ../win32xx/include/wxx_appcore0.h:111,
                   from ../win32xx/include/wxx_appcore.h:57,
                   from ../win32xx/include/wxx_wincore.h:96,
                   from frame.cpp:2:
  /usr/local/include/wine/msvcrt/wchar.h:398:23: error: conflicting declaration of C function ‘size_t mbstowcs(wchar_t*, const char*, size_t)’
   size_t        __cdecl mbstowcs(wchar_t*,const char*,size_t);
                         ^~~~~~~~
  </code></pre>
  
  <p>At this point I have run out of ideas. This is what I have understood so far:</p>
  
  <ul>
  <li>My system's libc and Wine's MSVCRT have conflicting definitions. (This was probably to be expected.)</li>
  <li>My system's libc++ is hardwired to work with my system's libc.</li>
  <li>Wine comes with a MSVCRT, but not with a C++ standard library implementation.</li>
  </ul>
  
  <p>The logical course of action with the information I have so far would be to look for a C++ standard library implementation that's compatible with Wine's MSVCRT, but I don't know of one. Does anybody here know of one?</p>