Thursday, January 21, 2010

Building for DOS, part 2: Setting up DJGPP under DOSEMU

First edit your /etc/dosemu/dosemu.conf: bump up the size of the available DPMI memory from the default 0x5000 KiB to something like 0x10000 or even 0x20000, as you might otherwise run out of memory on more complicated source files.
Now you can proceed with DJGPP install. -- I suggest you use the Zip File Picker, as I already mentioned in the previous post.

The Zip File Picker suggests you make the zip extracting from inside DOSEMU. But in my experience extracting from linux works ok and it's more comfortable. Do read the readme. But the first part of the installation can be as simple as this (you could pick a different target directory name, as long as it's not dev or dev/something):

get all the needed ZIP files in a directory
$ cd ~/.dosemu/drive_c
$ mkdir djgpp
$ for i in /path/to/*.zip; do unzip $i -d djgpp; done

Next step is setting the DJGPP environment variable and adding c:\djgpp\bin into the PATH. The easiest way to do this with dosemu is by editing autoexec.bat. A word of warning -- if the file is a symlink and you can't edit the file the symlink points to (as is the case with default Ubuntu install), you have to change the symlink into a (editable) copy first, e.g.:

$ cd ~/.dosemu/drive_c
$ cp autoexec.bat autoexec.bat.copy; mv autoexec.bat.copy autoexec.bat

As the file uses DOS line end characters (CR LF), if might look odd in some linux text editors (like mcedit). The easiest way is to edit the file from within dosemu -- fire up DOSEMU, then type:

edit autoexec.bat

The default dosemu autoexec.bat file sets up some environment variables and then plays some DOSEMU-specific tricks. So before the unix and lredir tricks insert these two lines:


The last step is adapting config.sys (use edit config.sys). Zip File Picker suggests config.sys is to contain these three lines:

shell=c:\dos\ c:\dos /e:2048 /p

On my ubuntu install, the "files=40" line is already present. So just "fcbs=40,0" needs to be added. The file also contains:

shellhigh=z:\ /e:1024 /p

It worked ok for me if I left it at "shellhigh" and just enlarged the environment size from 1024 to DJGPP-suggested 2048:

shellhigh=z:\ /e:2048 /p

Restart DOSEMU (exitemu in dosemu, then fire up DOSEMU again). If everything worked ok you should be able to build and run C (and optionally other languages, if you installed those too) programs in DOSEMU:

C:\test>gcc test1.c -o test1.exe
Hello World!

Note: On one of my boxes (running Ubuntu 9.10, DOSEMU 1.4.0+svn.1828-2ubuntu2) I was unable to get g++ versions 4.4.1 and 4.4.2 working. -- But 4.4.2 is working fine for me on Gentoo with dosemu-1.4.1_pre20091009. Here is the bug report.

It seems to be possible to work around the issue for the time being: Set $_cpu_emu = "vm86sim" in /etc/dosemu/dosemu.conf and use GCC version 4.3.2.


  1. Hi David;
    Thanx for posting this information.
    Worked well for me. I have this little app (little my modern standards, not so little by the historical standards of DOS)
    I just used you critical hint to get everything to build.
    The key is to edit the "/etc/dosemu/dosemu.conf" file, and tweak the DMPI memory from the default value of 5000
    to something bigger. DJGPP's "go32-v2.exe" program reports that I had 21meg of DPMI avail, but nothing would compile, until I took that up to 15meg. Then, everything flew like a daemon! Thanx.
    Just for the record (and the search engines), I am using Fedora 9.0 (the old "Sulphur" release, circa 2008), on a Acer TravelMate 6000-series laptop. I'm running DOSemu version (also probably old), and using latest DJGPP (which is circa 2002, I think), which uses gcc 4.7.2. This combo works fine.
    I am quite surprised. I get this decent-sized DPMI version of my little scientific-math-graphics app running at lightening speed, on my Linux X-windows/Gnome session. Passes all the regression tests, suprises the heck out of me. I have a clean build of a solid product. DOSemu is not bad. And as DOSemu and DOSbox-0.74 are being ported to every device, then one has the basis for a nice little virtualization model.
    Thanx again. The key for me was to do the edit to the "/etc/dosemu/dosemu.conf" file. Oh, another kinky issue was changing the name of the makefile from "MAKEFILE" to "makefile", and of course, setting the DJGPP path and "DJGPP" environment var.
    Thanx again..
    - Rus

    1. I'm glad the post was useful.

      Btw. the latest DJGPP seems to be quite new. It includes gcc 4.7.2 which has been released in 2012 - see It's true that DJGPP website looks as if it's not being maintained since the beginning of the 20th century, but it's still alive under the hood. :)