问题
I've been looking all over google for this but never got a clear answer.. I'm trying to write a simple hello world application and make it run under msdos (which I will be installing on a old rig lying around here).
But first things first, I've been trying to compile a normal console application and drop it in dosbox to test it out which doesn't work, just says it's invalid. So I assume I need something else to compile it with. Does this mean I'm obligated to build my code in a msdos environment? Even if this is the case, I have no clue at all how to do this, kinda a msdos dummy..
If anyone can shed some light on my case I would be very grateful!
P.S: I'm running a 64bit system
回答1:
You can use the free DJGPP compiler for DOS.
And here is the documentation for using DJGPP.
回答2:
I'm assuming that you mean actual DOS and not a command prompt running in Windows.
DOS is a 16-bit OS, so you will need a compiler capable of generating a 16-bit binary. A Windows console application is 32-bit, so it won't run under DOS. You don't have to build your code in a DOS environment, you will just need the right compiler.
As for compilers, you might want to check out OpenWatcom.
回答3:
Microsoft Visual C++ 1.52 is the only available version of a Microsoft C++ compiler that supports compiling 16-bit code.
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvc/thread/cfc848e8-a797-42a5-8537-892cfc234123
You need to find an old compiler that will generate 16bit COM files.
回答4:
Could running it on a 64bit system be an issue?..
Yes, 64-bit Windows cannot execute a 16-bit program. If you install a virtual PC with MS-DOS or a 32-bit Windows system, the virtual PC will be able to execute a 16-bit program.
Do you need to edit your question to say that you're using 64-bit Windows?
回答5:
It sounds like you are compiling a console app on a modern version of Windows and trying to simply copy it to an old DOS box. The problem is that DOS is not forwards compatible. You cannot run a program compiled with Windows 7 on pre-Windows versions of DOS. The simplest solution is to compile your programs on the DOS box itself. Alternatively, if you want to develop on a newer machine, you need to get a cross-compiler which targets the OS where you want to run your program.
来源:https://stackoverflow.com/questions/12806330/how-do-i-write-a-c-console-exe-which-i-can-run-on-msdos