Intro
djgpp is the gnu compiler set ported to DOS. it includes fortran, ada, and a few other compilers (maybe a lisp too), but the one we are focusing on right now is the tool pair gcc and gpp. Because it is a 32-bit compiler, Himem.sys is required to execute your programs. And if you want a decent executeable, you must link in cwsdpmi. with CWSDPMI, you can also execute them under 32-bit Windows, just not under 64-bit Windows.
Installation
download the beta, it has c++0x and most of the useful parts of TR1.
Make a directory for your downloaded files that is 8 characters or less and fits the 8.3 DOS filename specification (no spaces, single quotes, commas, preferably no periods), such as c:\djgpp or c:\djc
use the zip picker of you want the current stable version. I know you want to download the entire thing, but this is the safest way. fewer problems. beta version is at delorie.org
unpacking
- download all your zip files and unzip32.exe and csdpmi07b.zip (which you must get from the ftp mirror or ftom ftp://ftp.delorie.com/pub/djgpp/current/v2misc/), and move them into the same directory and then unzip. it is required to make sure that the directory you extract to has no spaces in it and I think is off the root (c:\). the -d directory switch and everything after it is purely optional, if you don't specify it, then you havew to extract from the same directory *to* the same directory.
- use their unzip program unzip32.exe. it deals with long filenames differently than your zip program. I get good results with
unzip32 -uLosa *.zip -d c:\djgpp452beta\
Make batch file to set up your environment variables
you will need to run this batch file in your command shell once to set environment variiables (like the PATH) before you run the compiler. since I installed a compiler in c:\djgpp452beta my f:\djgpp452beta.bat looks like:
set _DJBASEBS_=c:\djgpp462beta set _DJBASES_=c:/djgpp462beta set PATH=%_DJBASEBS_%\bin;%_DJBASEBS_%\allegro\bin;%PATH% set DJGPP=%_DJBASES_%/djgpp.env
Note the use of / instead of \ on the DJGPP variable! this is intentional! I usually add more to the path.
about the compiler
- long command-lines have been replaced with @ immediately followed by a filename which contains the list of files to be included. it might even work with any switches you want. example: gcc @files.lst
- OS: it runs under command.com only, so it requires specifically the 32-bit version of Windows if you are runing windows,which supplies DPMI memory access - it will NOT run only on a cmd shell under 64-bit unless you are running xp mode. for DOS, it requires a 386 with himem.sys or other XMS driver, which usually supplies DPMI memory access.
- DJGPP-compiled programs, and DJGPP can only address 15MB. sorry.
- if you can run the djgpp compiler, you can run a DJGPP program.
- DJGPP requiressome awkward steps to make an executable, including stubify and using file concatenation to put 2 exe's together. see my batch file.
- -W -Wall turns on all the warnings. catches pretty much everything that should be caught and maybe some things that probably can't be resolved.
- -isystem /libpq/ includes a directory as if it were a system directory. for instance, you can uze #include <whatever> if whatever were a file underneath /libpq/ so this can apply to libraries and such like pthreads if you can get it working.
- default binary output is a.out I believe.
Make a useable DPMI-enabled .exe (DOS executeable)
normally the executeables that come out of gcc are in COFF format, not in EXE format, and are not bound to a DPMI Server, and there's no DPMI support base, which the EXE will require, so you need CWSDPMI (a separate download via FTP). also, if you want smaller executeables than 600k, you should think about compiling with the -s (strip debug info) option. it should come down to 200-300k. I also like compiling with -O optimization level and -fpack-struct. you can use these commands in a makefile. I don't know if you can really do #3 with cat or not. you may have problems with ^Z characters if you do.
Switches: -s strips out the huge debugging stuff.
-fpack-struct packs structures so you don't have surprising and gaping holes in them, but it does not work with iostream, fstream, istream, ostream, or locale.
-O is the most optimization level you can get.
-O2 and -O3 causes corrupt/bad/bogus code. (has this been fixed in 4.5.2?)
-o filename sets the output file.
-std=c++0x on gpp uses the newer standard c++ libraries.
If it happens to be an EXE, it will generate a monolithic executeable.
response files can be used, where your source files and libs can be piled in a list, one per line, in a file, and then on the gcc command line you use @file instead of specifying files. this comes in handy if you have a lot of files.
to prevent your executables from using c:\cwsdpmi.swp swapfile which is the default, you need to get csdpmi07b.zip or similar version, and use stubify.exe on a copy of cwsdstub.exe so that it allocates 0 space for swap and the swap filepath is "", this will disable swap which defaults to c:\swapfile.swp or something similar. this only needs to be done to cwsdpmi.exe once.
- c:\djgpp452beta\bin\gpp -O -s -fpack-struct somefile.cpp someotherfile.cpp yetanotherfile.cpp -o a.exe OR c:\djgpp452beta\bin\gpp -O -s -fpack-struct -o a.exe @myfiles.lst
- exe2coff a.exe
- copy /b c:\djgpp452beta\bin\cwsdstub.exe+a a2.exe
- move a2.exe somefile.exe
- del a a2.exe a.exe a
Downloads
right click and pick save target as, or save link as. if you have Chrome or Safari which has neither of those options, simply click on the file and it will be downloaded. then move it to a place in your PATH if you have a utilities directory or make a new place in your PATH.
you can choose either, they do the same thing. the .cmd file only works on nt/2000/2003/2008/2008 r2/xp/vista/7/8/etc. which has the enhanced cmd.exe shell (but it's not guaranteed to execute djgpp or djgpp programs - it either works or it doesn't).
About the downloads
gp.cmd calls the ansi c or c++ compiler and makes executeables. it comes with help. internally it automatically sets the environment all by itself. it requires the beta version of the compiler.
gp.bat calls the ansi c or c++ compiler and makes executeables. it comes with help. internally it automatically sets the environment all by itself. it requires the beta version of the compiler.
you will want to choose ONE of the batch files (downloads), depending upon your system type. the .cmd file is for nt/2000/xp/2003/vista/2008/2008 r2/7/8/etc. those OS's have a greatly enhanced cmd.exe shell. you must have installed csdpmi07b.zip (or whatever the latest version is) from ftp://ftp.delorie.com/pub/djgpp/current/v2misc.
Will DJGPP and compiled apps work on my Windows system?
I have 3GB of RAM on XP Pro SP3 32-bit (also ran it under SP2) and they run just fine under my system. so the myth that 32MB of RAM is too much is just plain wrong.
A problem comes when you have a 64-bit system. a 64-bit system does not come with command.com natively. it only has the cmd.exe shell, which is NOT able to execute 32-bit djgpp programs or DOS programs because there is no NTVDM.
Windows 7 however, has the 32-bit-only Windows XP mode to run apps and because it is 32-bit, it has the command.com, even in the 64-bit windows 7, and therefore runs DOS apps. to make sure, I have verified it with someone who has 64-bit Windows 7 and who has XP Mode installed.
I don't know about Windows 8. would somebody please test and see if it has "Windows XP Mode" and runs DJGPP apps? I have a test app, use the .\dos\ directory to execute beep.exe from either command.com or a cmd.exe shell - either way, a command.com will be fired off and an NTVDM started, and thus the dos program will be run IF it's supported, but don't test using the .\win\ directory, that will always run.