在Mac OS上使用GCC为MS-DOS编译C程序(DOSBox)
我在 Mac OS X 上的 Snow Leopard 下运行 GCC 4.2.1。我想用它来编译我 15 年前写的一些旧的 C/C++ DOS 游戏,以便我可以在 DosBox。为此,它们显然需要编译为 DOS 可执行格式,谁能告诉我如何使用 GCC 来做到这一点?
谢谢!
I am running GCC 4.2.1 under Snow Leopard on Mac OS X. I want to use it to compile some old C/C++ DOS games I wrote 15 years ago so that I can run them under DosBox. To do this they obviously need to be compiled in DOS executable format, can anyone tell me how to do this using GCC please?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
DOSBox 在仿真下运行 16 位 x86 实模式代码。 OSX 10.6 上的常规 GCC 编译器针对 OSX 操作系统和 32 位 x86 保护模式,因此您无法使用它来构建在 DOSBox 中运行的代码。
您可以做的是在 DOSBox 本身中运行 DOS 编译器。 DJGPP 是 GCC 的 MS-DOS 端口,但它生成针对 DPMI 子系统的 32 位保护模式代码。我不清楚 DOSBox 是否支持 DPMI,但我想它确实支持,并且 DJGPP 本身位于 DOSBox 中兼容性列表,因此人们可以想象,如果它生成的代码没有对模拟硬件做任何异常的事情,那么它也可以运行。
Borland Turbo C 也在兼容性列表中,并且 TC 2.01 合法且免费。其他版本可以在其他地方下载,但我怀疑这种分发的合法性。
然而,更强大的解决方案可能是使用 VirtualBox< 在 OSX 上托管的虚拟机中安装正版 MS-DOS 或 DOS 兼容操作系统/a>.如果您没有 MS-DOS 的副本,您可以尝试 FreeDOS。
DOSBox runs 16 bit x86 real-mode code under emulation. The regular GCC compiler on OSX 10.6 targets the OSX operating system and 32 bit x86 protected mode, so you cannot use that to build code to run in DOSBox.
What you may be able to do is run a DOS compiler in DOSBox itself. DJGPP is an MS-DOS port of GCC, however it generates 32bit protected mode code targetted at the DPMI subsystem. It is not clear to me that DOSBox supports DPMI, but I imagine that it does, and DJGPP itself is in the DOSBox compatability list, so one would imagine that the code it generates might run also if it does not do anything too out of the ordinary to the emulated hardware.
Borland Turbo C is also on the compatability list, and TC 2.01 is legitimately available for free. Other versions are offered for download elsewhare, but I doubt the legality of such distribution.
A more robust solution however is probably to install a genuine MS-DOS or DOS compatible OS in a Virtual Machine hosted on OSX using VirtualBox. If you do not have a copy of MS-DOS, you might try FreeDOS.
可能有一些用处:
在 Debian 中编译 DOS 程序的问题
Might be of some use:
Question on compiling DOS programs in Debian
您的旧 DOS 游戏是为 16 位还是带有 DOS 扩展器的 32 位环境编写的?
如果是16位代码,GCC就没有任何用处了。您可能需要查看 OpenWatcom 或 OpenWatcom 。 digitalmars.com/features.html" rel="nofollow">Digital Mars,两者都声称支持 16 位 DOS(尽管我不知道它们在这方面的表现如何)。您可能必须在 Windows VM 中运行编译器(当然对于 Digital Mars,不确定 OpenWatcom)。
如果您正在寻找 32 位 DOS Extender 工具链,上述两个工具链也都声称适用于该工具链,但您也可以让 GCC 为您工作(DJGPP 可能会有所帮助 - 同样,我不知道它的工作效果如何,也不知道它是否可以从 Linux 或 Mac 环境进行交叉编译)。
Are your old DOS games written for 16-bit or for a 32-bit environment with a DOS extender?
If it's 16-bit code, GCC won't be of any use. You might want to look into OpenWatcom or Digital Mars, both of which claim 16-bit DOS support (though I have no idea how well they work for that). You may have to run the compiler in a Windows VM (certainly for Digital Mars, not sure about OpenWatcom).
If you're looking for 32-bit DOS Extender toolchain, both of the above also claim to work for that, but you might also get GCC to work for you (DJGPP might help - again, I don't know how well it works or if it'll cross compile from a Linux or Mac environment).