- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 wineg++
编译 C++ 程序时遇到问题。为了说明我的问题,我编写了两个测试程序。
#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;
}
#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 的固定大小整数类型不可用。这似乎很容易解决:
#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);
^~~~~~~~
在这一点上,我已经没有想法了。这是我到目前为止的理解:
根据我目前掌握的信息,合理的做法是寻找与 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/
这是我唯一可以问这个问题的地方,因为 WineHQ 论坛出于某种原因被锁定...所以请告诉我是否可以将 Winelib 静态链接到商业应用程序及其使用条款是什么 - 是否应在文档、应用程序的关于框等中
我正在开发一个在 Linux 上运行并使用 Wine 调用 Windows dll 的控制台应用程序。 虽然我能够调用 dll,但在运行 .exe 控制台应用程序时我得到了一些意外的输出。 例如: e
我有一个加载库的 Windows 可执行文件,我想创建一个将覆盖 Windows DLL 的 Winelib DLL。我已经搜索并尝试了 2 天,但它不起作用!请帮助我! 基本上,我创建 mydll.
我在使用 wineg++ 编译 C++ 程序时遇到问题。为了说明我的问题,我编写了两个测试程序。 消息框.cpp #include #include #include #include int
有一个 DLL(没有源代码,但希望里面没有花哨的东西)。打算写一个Linux应用程序来使用它。于是,GNU一路走来:原生Linux gcc/gdb/ELF等。 我在这里找到了一些解决方案:使用 Win
我喜欢 DFL GUI 工具包的几乎所有内容,只是它只适用于 Windows,因为它基本上是 Windows API 的一个漂亮的高级包装器。使用 Winelib 将这样一个工具包简单地移植到 Lin
我有一个 Windows DLL 和一个与 DLL 相关的 API。 DLL 是特定设备驱动程序的一部分,我想为此编写一个 Linux (Android 4.0) 软件。我读到可以在 Linux 软件
我是一名优秀的程序员,十分优秀!