简体   繁体   English

有没有办法使用<X11/Xlib.h>和<X11/keysym.h>与MinGW?

[英]Is there a way to use <X11/Xlib.h> and <X11/keysym.h> with MinGW?

I was surfing the IOCCC website and I stumbled upon a 1998 entry named banks which is a Flight Simulator by Carl Banks.我在浏览IOCCC网站时偶然发现了 1998 年名为bank 的条目,它是 Carl Banks 的飞行模拟器 I wanted to try it and so downloaded the files but as you may know (from MinGW) I am on a Windows system,sadly (specifically, Win-7 32-bit) and when I tried to use Cygwin and MinGW to compile the file it showed我想尝试一下,所以下载了文件,但您可能知道(来自 MinGW)我在 Windows 系统上,遗憾的是(特别是 Win-7 32 位),当我尝试使用 Cygwin 和 MinGW 编译文件时这显示了

banks.c:3:16: fatal error: X11/Xlib.h: No such file or directory
3 | #include       <X11/Xlib.h>
  |                ^~~~~~~~~~~~
compilation terminated.
make: *** [makefile:92: banks] Error 1

and the code banks.c included和代码banks.c包括

#include                     <math.h>
#include                   <sys/time.h>
#include                   <X11/Xlib.h>
#include                  <X11/keysym.h>

Is there a way to compile the file without using Linux?有没有办法在不使用 Linux 的情况下编译文件?

There is a Win32 port of X Window server called Xming, it is used rather often for connecting to remote Unix hosts. X Window 服务器有一个名为 Xming 的 Win32 端口,它经常用于连接到远程 Unix 主机。

If you are using MinGW with MSys2, there is a package called mingw-w64-libxcb , so compiling and using X11-based programs can be possible.如果您在 MSys2 中使用 MinGW,则有一个名为mingw-w64-libxcb的包,因此可以编译和使用基于 X11 的程序。

Regarding the program itself (banks.c), it is better (though not so straightforward) to compile it for WinAPI directly (yes, I know it sounds harder than simply running make, but the program is rather old and it probably uses non-standard and outdated extensions and peculiarities of the 1998 compilers, so it is better to debug/fix it in a familiar environment, which happens to be Windows in your case).关于程序本身(banks.c),最好(虽然不是那么简单)直接为 WinAPI 编译它(是的,我知道这听起来比简单地运行 make 更难,但该程序相当旧,它可能使用非1998 编译器的标准和过时的扩展和特性,因此最好在熟悉的环境中调试/修复它,在您的情况下恰好是 Windows)。 The source code (after de-obfuscation) looks like a graphics program centered around the源代码(去混淆后)看起来像一个以

for ( ; XPending (e) ; )

loop, which is directly translated to WinAPI's循环,直接翻译成 WinAPI 的

while (GetMessage(&msg, NULL, 0, 0))
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    ... all the code here
}

The window creation and key callbacks are also translated to WinAPI.窗口创建和键回调也被转换为 WinAPI。

EDIT1编辑1


The program works in X11 on Linux out of the box, but it also requires some data to be fed from stdin (that should not be an issue on Windows, but if you do not have "cat" installed, this will also be required).该程序在 Linux 上开箱即用,可在 X11 中运行,但它还需要从 stdin 提供一些数据(这在 Windows 上应该不是问题,但如果您没有安装“cat”,这也将是必需的) .

When I wrote it back in 1997, I definitely tested it on Windows using Cygwin, so I know it worked back then, and there should be no reason it wouldn't work now.当我在 1997 年写它时,我肯定使用 Cygwin 在 Windows 上测试过它,所以我知道它当时可以工作,现在应该没有理由不工作。 In Cygwin's package manager, you'd need to install a package called libx11-dev or something to that effect (the X11 development libraries), as well as an X server (probably called something like Xorg), and of course GCC and the development tools like make.在 Cygwin 的包管理器中,您需要安装一个名为 libx11-dev 的包或类似的东西(X11 开发库),以及一个 X 服务器(可能称为 Xorg 之类的东西),当然还有 GCC 和开发make 之类的工具。 You should be able to launch a Cygwin X server from the start menu, and in the subsequent terminal window inside the X window, you can cd to the folder where you unpacked the IOCCC winners and run make.您应该能够从开始菜单启动 Cygwin X 服务器,然后在 X 窗口内的后续终端窗口中,您可以 cd 到解压 IOCCC 获胜者的文件夹并运行 make。 (More detailed information on Cygwin is beyond the scope of this reply; I'm going mostly from memory as I haven't used Cygwin in years.) (关于 Cygwin 的更多详细信息超出了本回复的范围;我主要是凭记忆来的,因为我多年没有使用 Cygwin。)

But if you want my opinion, don't bother with Cygwin.但是如果你想要我的意见,不要打扰 Cygwin。 A much easier way to build and run it would be to just get a Live CD for Linux and boot up Linux directly, and run it there.构建和运行它的一种更简单的方法是获取 Linux 的 Live CD 并直接启动 Linux,然后在那里运行它。 Some Live CDs have dev tools like GCC on them, others let you download GCC easily enough.一些 Live CD 上有像 GCC 这样的开发工具,其他的则可以让您轻松下载 GCC。 Knoppix is a common choice. Knoppix 是一种常见的选择。

(If you want to be really kinky, you could try installing Windows Subsystem for Linux so you can run Linux programs natively on Windows.) (如果你真的想变态,你可以尝试安装适用于 Linux 的 Windows 子系统,这样你就可以在 Windows 上本地运行 Linux 程序。)

X11 is a windowing system for Unix-based operating systems, therefore it cannot be used on Windows natively . X11是基于Unix的操作系统窗口系统,因此它不能在Windows本地使用。

But there's a way to both run X11 programs and compile them using Cygwin compiler.但是有一种方法可以运行 X11 程序并使用 Cygwin 编译器编译它们。 For that purpose you will have to use Cygwin/X , which should contain X11 libraries.为此,您必须使用Cygwin/X ,它应该包含 X11 库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM