用wineg ++ / winelib编译C ++程序的问题

时间:2017-12-22 18:46:51

标签: c++ windows winapi wine winelib

我在使用wineg++编译C ++程序时遇到问题。为了说明我的问题,我写了两个测试程序。

msgbox.cpp

#include <algorithm>
#include <iterator>
#include <cstdio>

#include <windows.h>

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;
}

frame.cpp

#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();
}

第二个程序使用Win32++库,我无法推荐。

使用交叉编译器编译和运行两个程序:

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*

但是我想使用winelib以便我可以同时使用Windows API和Unix库。这是我先试过的:

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 <process.h>
            ^~~~~~~~~~~
compilation terminated.
winegcc: g++ failed

然后我阅读wineg++的手册页,其中写道:

  

-mno-cygwin的
  使用Wine实现MSVCRT,而不是链接到主机系统libc。这对于绝大多数Win32应用程序来说都是必需的,因为它们通常依赖于MSVCRT的各种功能。 MinGW编译器也使用此开关在Windows上链接MSVCRT,而不是链接到Cygwin libc。与MinGW共享语法可以很容易地编写在Wine,MinGW + MSYS或MinGW + Cygwin下工作的Makefile。

所以我再次尝试使用-mno-cygwin,并收到一条2000行错误消息,该消息以:

开头
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));
        ^~~~~~~

所以似乎C99的固定大小整数类型不可用。这似乎很容易解决:

frame.cpp

#include <stdint.h>
#include "../win32xx/include/wxx_wincore.h"
#include "../win32xx/include/wxx_frame.h"
// etc. etc. etc.

我再次尝试,但得到了一个不同的2000行错误消息,该消息以:

开头
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);
                       ^~~~~~~~

此时我已经没有想法了。这是我到目前为止所理解的:

  • 我的系统的libc和Wine的MSVCRT定义相互矛盾。 (这可能是预期的。)
  • 我的系统的libc ++与我的系统的libc一起使用。
  • Wine附带一个MSVCRT,但没有C ++标准库实现。

迄今为止我所掌握的信息的逻辑行动方式是寻找与Wine的MSVCRT兼容的C ++标准库实现,但我不知道其中的一个。这里有人知道吗?

1 个答案:

答案 0 :(得分:1)

我能想到的唯一解决方案是坚持使用系统libc并编写自己的process.h。该文件应该#include具有Win32 ++函数所需的标准头文件,或者提供它们自己的那些函数实现。如果Win32 ++在没有特定函数的情况下无法编译但你的程序实际上并不依赖于该函数,那么该函数的实现只能返回0或其他假值。

如果系统libc有一个Win32 ++要求的头文件,但是该文件没有声明Win32 ++期望的所有函数,那么你必须编写一个头文件,例如win32xx-compat.h来定义这些函数并且在任何Win32 ++标头之前#include