Computing: Computer Basics

FreeDOS: Installing and running DJGPP.

"DJGPP is a complete 32-bit C/C++ development system for Intel 80386 (and higher) PCs running DOS. It includes ports of many GNU development utilities. The development tools require an 80386 or newer computer to run, as do the programs they produce. In most cases, the programs they produce can be sold commercially without license or royalties." This is how they describe the product on the DJGPP page of Delorie. You can also call it the port of the GNU compiler collection from Unix-like systems to DOS and Windows.

The following tutorial describes the installation of DJGPP 2.0.5. The DOS platform used is FreeDOS 1.3 RC5, the way to proceed on MS-DOS or other DOS systems should be similar. The tutorial only covers the basics (C and C++ development using RHIDE), without condidering special libraries (like Allegro), or other GNU programming languages (FORTRAN, ADA, Pascal...) that may be installed on the top of DJGPP.

Downloading DJGPP.

DJGPP is a really huge project, composed of a large number of packages for different platforms. Which packages (individual .zip files) you need depends on what you intend to use the software for. Browsing the files and manually choosing what to install would be rather hard, I guess. Fortunately, Delorie offers a lots simpler way to find what you need. On their DJGPP Zip File Picker page, you have the possibility to fill out a form and, based on your selections, the web application will generate a page with the links to the corresponding .zip files. In the first part of the form, you can choose if you want to build or only to run DJGPP applications (obviously to build them in our case), choose the operating system (DOS in our case), choose if you want to download the documentation files and select which programming languages you want to be installed: C, C++, Objective C and Assembler in my case.

DJGPP on FreeDOS: Components selection using the Delorie Zip File Picker web application [1]

Further down on the form, you can select an editor/IDE (RHIDE, similar to Borland's IDE works fine), choose if you want the text-mode GNU debugger (actually not needed if you install RHIDE that includes a debugger) and make your selections for the extra stuff shown on the page (note, that the components shown are only the most popular ones; to view them all, visit the download site itself). I selected all of them, except the sources (I did not yet try out anything of these, so I can't say how well or not they work).

DJGPP on FreeDOS: Components selection using the Delorie Zip File Picker web application [2]

The following screenshot shows the packages (.zip files) that the file picker application has selected. Note that files with a name ending in -b are binaries; those ending in -d are documentation.

DJGPP on FreeDOS: Component download suggestions (Delorie Zip File Picker)

Download the files and (the simplest way to proceed, I would say) burn them onto a CDROM (aka make an ISO to be used in your virtualization software or virtual CD-drive) in order to access them on your FreeDOS machine.

Installing DJGPP.

When unzipping the different packages, please be aware of the following:

The screenshot shows the content of my CDROM (mounted as drive letter F:).

DJGPP on FreeDOS: Components (zipped packages) ready to be installed

Create the directory where DJGPP should be installed and copy the “readme” and “copying” files to this directory. Copy the Dislin unzip utility to your FreeDOS executable directory, renaming it (for example to unzip8.exe) in order not to overwrite the FreeDOS unzip utility.
    mkdir c:\djgpp
    cd c:\djgpp
    copy unzip.exe c:\freedos\bin\unzip8.exe

Using a text editor (on FreeDOS or on the host of your VMs), create a batch file including the commands to unzip all packages on the CDROM to the DJGPP installation directory (you can extract the packages one by one, if you prefer). Here the content of my UNZIPALL.BAT:
    cd \djgpp
    unzip8 f:\
    unzip8 f:\
    unzip8 f:\
    unzip8 f:\
    unzip8 f:\
    unzip8 f:\
    unzip8 f:\
    unzip8 f:\
    unzip8 f:\
    unzip8 f:\
    unzip8 f:\
    unzip8 f:\
    unzip8 f:\all422a*.zip
    unzip8 f:\all422b*.zip
    unzip8 f:\
    unzip8 f:\
The archives on the CDROM (drive F:) are unpacked to the current directory (actually C:\DJGPP).

DJGPP on FreeDOS: Content of the DJGPP installation directory

You should change the settings in FDCONFIG.SYS: Setting the number of files to 40 and the fcbs to 40,0 (if the directives don't exist, add them, otherwise change them; if there are higher values in your file, let these untouched); setting the value of the /E parameter of the SHELL directive to 2048 (normally, you'll have to replace /E:1024 by /E:2048). Here these directives in my FDCONFIG.SYS (the SHELL directive in your file may be somewhat different):

You will also have to add C:\DJGPP\BIN to the PATH, and create the new environment variable DJGPP set to C:\DJGPP\DJGPP.ENV. If you often work with DJGPP, you can include these settings in FDAUTO.BAT. Otherwise creating a separate batch file is better practice. The commands normally are as follows:

Testing the C compiler.

We can now perform a quick test of the DJGPP installation by trying to build a simple "Hello World" C program. Here the sample source code:
    /* Hello World */
    #include <stdio.h>
    int main(void) {
        printf("\nH E L L O W O R L D !\n\n");
        return 0;

The GNU C compiler is called gcc and may be invoked with just 2 parameters: 1. the name of the C source file, 2. the name of the executable to create preceded by "-o" (without the quotes; the "o" meaning "output"). In our case (supposed that we actually are in the directory where hello.c is located and that we want to have the executable there, too):
    gcc hello.c -o hello.exe

The screenshots below show the build command (on the left) and the execution of the program (on the right).

DJGPP on FreeDOS: Building the sample C program 'Hello World!'
DJGPP on FreeDOS: Running the sample C program 'Hello World!'


The Delorie DJGPP packages for DOS include RHIDE, an IDE (editor plus debugger) for C. If you unzipped all packages shown in the directory listing of my CDROM containing the downloads at the beginning of the tutorial, RHIDE is installed and ready to be used. Just type "rhide" (without the quotes) to start it.

I want however describe here how, on my FreeDOS system, I take advantage of custom batch files, a different one for each programming language, to start the development related programs. This has several advantages:

I have created a special directory (C:\FREEDOS\BATCH) where I place all my custom batch files, and normally I name them with a number sign (#) as last character, just to be sure that I run my batch file and not possibly a compiler or other program with that name. So, I use BP#.BAT to start the Borland IDE for Turbo Pascal, VB#.BAT to start the Microsoft Visual Basic environment, PERL#.BAT to start SET's Editor, that I use with Perl 5. And, for DJGPP development, I created DJGPP#.BAT; here its content:
    @echo off
    set DEVEL=djgpp

First, I add C:\DJGPP\BIN (that contains all DJGPP executables, including RHIDE.EXE) to the PATH. You may wonder what's this %PATH0% (instead of normal %PATH%). It's a custom environment variable that I set equal to %PATH% in my FDAUTO.BAT, and that as a difference with %PATH% is never changed. This avoids the PATH variable to become too long by adding specific directories for the execution of specific programs (and containing directories that are no longer needed).
The DEVEL environment variable takes track of the last programming environment used (you can ignore it here if you want). DJGPP is an environment variable that (as we saw in the preceding section) has to be set with the DJGPP development software.
Then, the current directory is set to D:\DEVEL\DJGPP, the folder with my DJGPP source code. And finally, RHIDE (the IDE) is started.

So, typing DJGPP# executes the commands above and the IDE starts up, as shown on the screenshot below.

DJGPP on FreeDOS: Start-up of the RHIDE integrated development environment

With the current directory having been set to D:\DEVEL\DJGPP, the RHIDE File > Open menu command directly opens the directory with the DJGPP source code, in particular with our HELLO.C sample, that we can now load into the editor.

DJGPP on FreeDOS: Sample 'Hello World' C program opened in RHIDE

We can use the menu command Compile > Compile to compile the source in the active editor window, or Compile > Build All to build a file or project (creating an executable in the same directory than the source). If everything is ok, the message "no errors" will appear below "Creating hello.exe" in the Messages window.

You can run the executable from within RHIDE by choosing the menu command Run > Run (screenshot on the left). If there was no runtime error, an information box with the message "Program exit code: 0 (0x000)" pops up (screenshot on the right).

DJGPP on FreeDOS: Running a sample C program from within RHIDE [1]
DJGPP on FreeDOS: Running a sample C program from within RHIDE [2]

To view the program output, choose the menu command Window > User Screen (screenshot on the left). This opens the DOS shell with the last input and output that was made there (screenshot on the right), in our case the execution of DJGPP#.BAT, that starts RHIDE and then the output of our "Hello World!" program. To return to the editor window of the IDE, hit the ENTER key.

DJGPP on FreeDOS: Running a sample C program from within RHIDE [3]
DJGPP on FreeDOS: Running a sample C program from within RHIDE [4]

To terminate this tutorial, lets build a C++ program using RHIDE. Here is the code (yet another "Hello World" program):
    #include <string>
    #include <iostream>
    using namespace std;
    int main () {
        string s1 = "Hello,";
        string s2 = "World!";
        cout << s1 + " " + s2 << endl;
        return 0;

The screenshots show the build of the programs, with the "no errors" message (at the left), and the program execution, in the User Screen window (at the right).

DJGPP on FreeDOS: Build of a sample C++ program using RHIDE
DJGPP on FreeDOS: Execution of a sample C++ program using RHIDE

If you find this text helpful, please, support me and this website by signing my guestbook.