I have installed MS-DOS 6.22 on a VirtualBox virtual machine, everything is working well, the purpose of doing that is to compile a program written in the C language that displays and edits bits in the (virtual) RAM. However, I need a way to install a C compiler on the virtual MS-DOS operating system.
-
Strange question I never wrote a exe file for DOS I just know that you need a LE file instad of a classic windows PE file. A .com file would be an alternative which is AFIK part of every exe file. – rekire Feb 26 '13 at 18:34
-
@rekire Actually, you need an MZ file. LE is for VxD drivers and OS/2 2.0 applications. See https://en.wikipedia.org/wiki/.exe for details. MZ is also what is part of every EXE. (`.com` is just a raw blob of machine code to be copied into memory and started. That's why it has so many limitations.) – ssokolow May 29 '18 at 08:14
9 Answers
Here are a bunch of details others have missed:
Nobody mentioned DJGPP at all.
It's a protected-mode DOS port of GCC and probably has the largest selection of libraries and guides available of any of the open-source options. (Including a Turbo Vision port with an installation HOWTO)
No matter what you're trying to do, OpenWatcom (source) is likely to meet your needs.
OpenWatcom still includes the free license to use DOS/4GW that made it so popular back in the day. (When you see a game like DOOM saying "DOS/4GW Protected Mode Runtime" when it starts, that means that it was built using Watcom C/C++, because DOS/4GW is the special Watcom bundle version of DOS/4G.)
In fact, DOS/4GW's creator was trying to dig up the source code for a newer version of DOS/4GW to contribute to Open Watcom when he passed away.
If you don't want nostalgia, OpenWatcom bundles newer, better alternatives to DOS/4GW, like DOS/32 and PMODE/W.
If you want to putter around with Windows 3.1 programming, OpenWatcom includes Win386, a 32-bit extender for Window 3.x which was used by companies like Sierra for their Windows 3.1 games before Microsoft produced their own "Win32s" 32-bit API addon.
OpenWatcom can target all supported platforms from a single install. (I use it to build various DOS and Windows test EXEs from Linux.)
OpenWatcom can target a lot of retro-platforms:
- COM files
- real-mode EXEs (there's a separate set of options to select minimum CPU requirement)
- protected-mode EXEs (with your choice of several extenders)
- Windows 3.1 EXEs (with or without the Win386 extender)
- Lots of other formats you probably don't care about
If your project must run in real mode (ie. no DJGPP) and you want something with a more modern optimizer than the one in Open Watcom C/C++, there's a fork of GCC named GCC IA16 that you can try. (Though I don't know how complete its support is for the various memory models and calling conventions used in the 16-bit x86 ecosystem.)
If you want something that'll let you run the IDE and compiler on ancient hardware, the Pacific C compiler and IDE list a 286 CPU as their minimum requirement but can also be run in DOSEMU for easy integration into Linux-based build automation.
Here are a few other free C compilers for DOS, though they lack the huge ecosystems DJGPP and OpenWatcom have:
You may also want to run the UPX compressor on the EXE files you build so you'll have more free space on any floppy images you make. (Don't forget to run it with --8086
if you're targeting something older than a 386.)
It's capable of compressing EXE, COM, and SYS files and using this sort of executable compression was commonplace back in the day.
(However, two of the three major formats UPX doesn't compress are OS/2 and Windows 3.1 executables. I'm still looking into the best option for those, given that LxLite doesn't get along with OpenWatcom-generated EXEs.)

- 14,938
- 7
- 52
- 57
The Turbo C compiler for DOS is just awesome, and freeware.
Official site link http://edn.embarcadero.com//article/20841
Also there are Microsoft QuickC but I don't know how hard is to find it.
Or Watcom C, but I don't know if their OpenWatcom version works with DOS

- 6,197
- 5
- 34
- 51
-
-
2OW works in DOS and compiles for DOS (even from under Windows), no problem there. There are several sets of binaries, though (DOS and Windows). – Alexey Frunze Feb 27 '13 at 09:47
-
1thanks for the help, i've downloaded the files, after i registered an account, after that, i did a floppy disk image of the first downloaded disk, set it in the virtual floppy device, wrote in DOS "cd A:" nothing happened, again "cd A:" it says "divide overflow". the same thing happened when i tried for the virtual cd/dvd disk with @Alos answer :( – Tarek Mar 01 '13 at 16:01
-
I ordered a laptop for me. (right now I rely on android devices), when it arrive, if I remember I will try to see for that :) – speeder Mar 01 '13 at 17:26
-
-
Yay, it arrived! But I am reading this over and over again and... I cannot remember what I was going to test. Care to explain again? – speeder Dec 05 '14 at 23:50
-
QuickC isn't the only Microsoft compiler capable of targeting DOS from DOS. In fact, it's not even the best. Among my old floppies, I have the last release of QuickC's semi-successor before it became Visual C++, "Microsoft C/C++ 7.0". (I say semi-successor because they coexisted while QuickC was being merged in.) Heck, if you're OK with using a Windows 3.1-based IDE on top of your DOS, Visual C++ 1.x can target DOS and it came bundled with Visual C++ 2.x (1.51 on the same CD) and Visual C++ 4.x (1.52 on a separate CD) for backwards-compatibility with old codebases. – ssokolow May 29 '18 at 08:03
I have installed the compiler and it worked successfully, if you want the ova here is the link MS-DOS ova with C compiler
To open the compiler:
cd TC
TC
and that's it! You can write C and compile. The best part is that you can deal with registers and memory without any restriction.
You may want to try Open Watcom or Borland Turbo Series. There are other options but best are those 2 imho.

- 1,120
- 2
- 23
- 28
There are a number of compilers here:
http://www.compilers.net/dir/free/compilers/ccpp.htm
Very specifically, I have used the "Pacific C" for several different fun projects and I was pleased with both the ease of use and overall compatibility.
I was able to chase down a new URL for the download:
http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/devel/c/pacific/

- 23,369
- 6
- 54
- 74
Open Watcom has a C compiler that will work on DOS: Open Watcom
You can save it and then create a virtual floppy with it: virtual floppy how to
This should let you install it on your virtual machine.

- 2,657
- 5
- 35
- 47
-
thanks for the help, i've downloaded a file with name "open-watcom-c-dos-1.9" with 80 MB size, made an iso of it, set it as a virtual cd/dvd disk, then wrote in DOS ,"cd B:", nothing happened, again "cd B:", it says "Divide overflow"...... i given up... – Tarek Mar 01 '13 at 15:55
-
2@AmbiguousTk I would not give up it seems that Divide overflow has to do with how the system is configured. Can you access the c drive on the vm? – Alos Mar 01 '13 at 16:11
The Borland C++ 4.53 is the most capable, as it can output DOS (in all memory models) and Windows 3.1 and 95 executables, from several IDEs, either a DOS or Windows one. It includes command line tools, but again, it has to be hosted on a PC platform or something like DOSBox.
This original package for Borland C 4 was fairly hefty, but not nearly as insane as the literal bookshelf which came with Borland C++ 3.1. Borland C++ 3.1 is more than likely the heaviest and largest retail commercial software product box in history.
Embarcadero Technologies has released Borland C++ compiler as freeware some time ago. Sadly there's no IDE, only command line tools.

- 362
- 2
- 14
-
He asked for C, not C++, and Embarcadero released Turbo C, that is a IDE. – speeder Feb 26 '13 at 18:53
-
According to [this page](http://www.embarcadero.com/products/cbuilder/free-compiler) there's no IDE included, only command line tools. – cesarse Feb 26 '13 at 19:13
-
Read my answer, you clearly answered without reading if a duplicate answer existed or not. Specially, read the link on it, and pay attention that C and C++ are not the same. – speeder Feb 26 '13 at 19:17
-
1+1 for a all-in-one (legal) download. Indeed C and C++ are not the same, but bcc32 knows how to behave according to file extension. – cesarse Feb 26 '13 at 19:39
-
2That C++ compiler supports C. But it runs only in Windows and compiles only for Windows. – Alexey Frunze Feb 27 '13 at 09:46