1. About DJGPP

DJGPP is an environment to build DOS 32bit binaries, in this regard somewhat similiar to HX. It has a built-in DOS extender called GO32, which requires a DPMI 0.9 host to run. Usually the free DPMI host CWSDPMI is supplied with DJGPP. Unlike HX, DJGPP contains a full programming environment, based on the GNU C/C++ compiler frontend gcc. During the past 15 years many libraries and tools were written for DJGPP, some of them rather unique.

2. Using DJGPP for HX

HX's focus is on Win32, it uses the PE file format. This allows to reuse many Win32 development tools, but there are some limitations. Being able to use the DJGPP resources and libraries lowers these limitations. The one issue where DJGPP is not compatible with HX is that DJGPP doesn't produce true-flat (or "zero-based") binaries. This issue is something which can be cured by modifying DJGPP's link step. As a side effect, from DJGPP's point of view, two benefits are achieved: The final binary is a HX DOS PE binary. Such binaries run as DOS applications in any environment, even if launched in a Windows DOS box.

3. Details

To make DJGPP produce HX PE binaries, the linker step has to be divided into 3 parts: It should be mentioned that - besides the small startup module CRT0.S, which is GO32 specific and therefore has to be replaced - all modules which are linked into the binary are still 100% DJGPP.

4. Example

This is an example for a Makefile to create a HX PE binary with DJGPP:

NAME=hello

$(NAME).exe: $(NAME).bin
	link @<<
$(NAME).bin /out:$(NAME).exe /fixed:no /subsystem:console 
/map:$(NAME).map /entry:start /stub:..\..\Bin\dpmist32.bin
<<
	pestub -q -n -w -x $(NAME).exe

$(NAME).bin: $(NAME).o djgpp.ld
	ld -T djgpp.ld -r -s -Map $(NAME)_.map $(NAME).o crt0hx.o -lc -lgcc -o $(NAME).bin 
	ldfix $(NAME).bin

$(NAME).o: $(NAME).c makefile
	gcc -c -o $(NAME).o $(NAME).c
 

Instead of a make file one can also use a batch file:
c:\>gcc hello

where gcc is a simple DOS batch file like this one:
@echo off

if "%1"=="" goto usage
\djgpp\bin\gcc.exe -c -O %1.c -o %1.o 
if errorlevel 1 goto end

\djgpp\bin\ld.exe -r -s -T djgpp.ld -Map %1_.map %1.o crt0hx.o -lc -lgcc -o %1.bin
if errorlevel 1 goto end

..\..\Bin\ldfix %1.bin
if errorlevel 1 goto end

link %1.bin /nologo /subsystem:console /entry:start /out:%1.exe /fixed:no /map:%1.map
if errorlevel 1 goto end

..\..\Bin\pestub -q -n -w -x %1.exe
goto end

:usage
echo usage: gcc source_file (without .C extension)

:end

5. Downloads

(For HX v2.11+, no additional download is needed anymore, everything is contained in hxdev.zip already.)