gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 05:06:24 35 4
gpt4 key购买 nike

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

消息框.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;
}

框架.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
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.

所以我再次尝试使用 -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 的固定大小整数类型不可用。这似乎很容易解决:

框架.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++ 标准库实现,但我不知道有一个。这里有人知道吗?

最佳答案

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

如果系统 libc 有一个 Win32++ 要求的头文件,但该文件没有声明 Win32++ 期望的所有函数,您将不得不编写一个头文件,例如 win32xx-compat.h 定义了这些函数,并且 #include 它位于任何 Win32++ header 之前。

关于c++ - 使用 wineg++/winelib 编译 C++ 程序的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47946016/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com