How to Set Up a Development Environment on FreeDOS
A complete walkthrough installing a C compiler and assembler on FreeDOS and building your first program — for anyone wanting to write software for DOS rather than just run it.
Writing software for FreeDOS means working with tools built for the same real-mode x86 environment covered elsewhere on this blog — this walks through installing a free, still-actively-usable C compiler and building a first program.
Step 1: install Open Watcom, a free, capable DOS-targeting C/C++ compiler
Download the Open Watcom installer, run it, and select
the DOS target platform during installation.
Open Watcom remains actively maintained and freely available specifically because it continues to be the most practical modern choice for genuine DOS software development, supporting both 16-bit real-mode and 32-bit protected-mode (DOS extender) targets.
Step 2: set up the environment variables Open Watcom needs
SET WATCOM=C:\WATCOM
SET PATH=%PATH%;%WATCOM%\BINW
SET INCLUDE=%WATCOM%\H
Adding these lines to AUTOEXEC.BAT makes the compiler and its headers available from any directory, rather than needing to reference full paths every time.
Step 3: write a minimal C program
/* hello.c */
#include <stdio.h>
int main(void) {
printf("Hello from FreeDOS!\n");
return 0;
}
Step 4: compile it for real-mode DOS
wcl -l=dos hello.c
wcl is Open Watcom’s compile-and-link driver; -l=dos targets a standard 16-bit real-mode DOS executable — the most broadly compatible target for software meant to run on genuinely old hardware or accurate emulation.
Step 5: run the compiled program
hello.exe
Step 6: write and assemble a simple assembly program, if going lower-level
; hello.asm
.MODEL SMALL
.STACK 100h
.DATA
msg DB 'Hello from assembly!$'
.CODE
main:
mov ax, @data
mov ds, ax
mov ah, 09h
lea dx, msg
int 21h
mov ah, 4Ch
int 21h
END main
wasm hello.asm
wlink name hello.exe file hello.obj
wasm is Open Watcom’s assembler — useful for the kind of direct interrupt-level programming covered in the FreeDOS interrupts deep-dive, where C’s abstractions aren’t what you actually want.
Step 7: use a build automation batch file for anything beyond a single file
@ECHO OFF
wcl -l=dos -fe=myprogram.exe main.c helper.c utils.c
A simple batch file wrapping the compile command saves retyping a growing list of source files and flags as a project grows beyond a single-file program.
Step 8: debug with Open Watcom’s included debugger
wd hello.exe
wd provides source-level debugging for programs compiled with debug information (-d2 compiler flag) — genuinely useful rather than a token feature, for anything beyond the simplest programs.
Why Open Watcom specifically, rather than a more modern cross-compiler
Open Watcom targets real DOS execution environments natively and directly, understanding real-mode segmented memory and DOS’s actual calling conventions without needing a compatibility shim — a genuinely different (and for DOS-specific work, more appropriate) approach than cross-compiling with a modern toolchain never designed with 16-bit real-mode DOS as a first-class target. For anyone actually writing software meant to run well within DOS’s own constraints, rather than just barely running under it, a DOS-native toolchain like this one remains the more direct, better-supported path.