The Borland Win32 Compiler Guide

How to compile and build Windows (Win32) applications with the free Borland compiler.

© Guy Lecky-Thompson

This article takes the reader through the acqisition, installation, and setup of the Borland compiler, and shows how to make and use a makefile to build Win32 programs.

Getting the Borland Compiler

The Borland BCC55 compiler can be downloaded from Borland's CodeGear web site (www.codegear.com), upon filling out a registration form. It is free, as are all the Borland C++ Builder tools that come with it, but users are required to give the personal details before they can obtain the package. It is well worth the effort.

Once it has downloaded, it can be installed.

Installing and Setting up the Borland Compiler

The downloaded file should be double-clicked, and the setup process will begin. If the user chooses all the defaults, the compiler will be installed in C:\BORLAND\BCC55. There are usually no good reasons to change the default settings, but if they are altered, then the reader will have to make their own substitutions for this path in the remainder of these instructions.

Before it can be used, the complier will need some configuration. It is a command line file, and as such does not have a Windows interface. This should not scare the reader off, it is just something to be aware of - there is no 'interface', and as such, there is a little magic involved in getting it to work. Following these (sometimes abstract) instructions will enable that magic to be mixed in.

Start notepad (or your favorite text editor), and copy the following lines into a blank document:

-I"c:\Borland\Bcc55\include "
-L"c:\Borland\Bcc55\lib "

Save the document as C:\BORLAND\BCC55\BIN\BCC32.CFG and start a new one. Copy the following lines into the new document:

-L"c:\Borland\Bcc55\lib "

This document can be saved as C:\BORLAND\BCC55\BIN\ILINK32.CFG and Windows restarted.

Creating a Batch file and Make file for Win32 Projects

To build a Win32 project from source (that the reader has created themselves), we need three things:

The batch file kicks off the build process. The make file tells the compiler, and linker, what files to include in the project. We also put a few commands in the batch file to enable us to view the results of the compile operation, and tidy up after ourselves. In cases where the build succeeds, the application will be started.

The batch file will remain roughly the same across all projects, with only the make_file_name.mak and application_name.exe needing to be replaced with the real name of the make file and application. This make file is based on a template which we shall cover below. The batch file contents can be cut and pasted from the following:

PATH=C:\BORLAND\BCC55\BIN;%PATH%
del *.exe
del *.obj
del *.res
make -fmake_file_name.mak err.txt
if exist application_name.exe goto RUN_EXE
:EDIT_ERR
call notepad.exe err.txt
:RUN_EXE
call application_name.exe
if exist err.txt delete err.txt
:END

A few points to note:

The file should be saved in the folder where the source code for the project will be stored. The first line (PATH=...) tells Windows where to find the compiler. The extension to the file should be .BAT ; a Windows (DOS) batch file.

The make file contains all the dependencies (source files) that the compiler will need in order to make the object code that can be used by the linker to create the application. The following is a skeleton (template):

APP = application_name
EXEFILE = $(APP).exe
OBJFILES = $(APP).obj object_file_names
RESFILES = $(APP).res
LIBFILES =
DEFFILE =
.AUTODEPEND
BCC32 = bcc32
ILINK32 = ilink32
BRC32 = brc32
CFLAGS = -c -tWM- -w -w-par -w-inl -W -a1 -Od -I"C:\borland\bcc55\include"
LFLAGS = -aa -V4.0 -c -x -Gn -L"C:\borland\bcc55\lib"
RFLAGS = -X -R
STDOBJS = c:\borland\bcc55\lib\c0w32.obj
STDLIBS = import32.lib cw32.lib
$(EXEFILE) : $(OBJFILES) $(RESFILES)
$(ILINK32) $(LFLAGS) $(OBJFILES) $(STDOBJS), $(EXEFILE), ,
$(LIBFILES) $(STDLIBS), $(DEFFILE), $(RESFILES)
clean:
del *.obj *.res *.tds *.map

From the above, application_name and object_file_names will usually need to be replaced. For each of the object file names (in the format file_name.obj) there shoiuld be a corresponding source file (ending in .c or .cpp). By a similar token, the file containing the entry point to the application - the WinMain function - should carry the name of the application, as specified in application_name.

So, for example, if a project contains a file MyApp.cpp with the WinMain function (and other Win32 bootsrap code) in it, a resource file MyApp.res, and a source file to handle strings, called MyString.cpp, then we would end up with the following lines in the make file:

APP = MyApp
EXEFILE = $(APP).exe
OBJFILES = $(APP).obj MyString.obj
RESFILES = $(APP).res
LIBFILES =
DEFFILE =
.AUTODEPEND
BCC32 = bcc32
ILINK32 = ilink32
BRC32 = brc32
CFLAGS = -c -tWM- -w -w-par -w-inl -W -a1 -Od -I"C:\borland\bcc55\include"
LFLAGS = -aa -V4.0 -c -x -Gn -L"C:\borland\bcc55\lib"
RFLAGS = -X -R
STDOBJS = c:\borland\bcc55\lib\c0w32.obj
STDLIBS = import32.lib cw32.lib
$(EXEFILE) : $(OBJFILES) $(RESFILES)
$(ILINK32) $(LFLAGS) $(OBJFILES) $(STDOBJS), $(EXEFILE), ,
$(LIBFILES) $(STDLIBS), $(DEFFILE), $(RESFILES)
clean:
del *.obj *.res *.tds *.map

We would then substitute MyApp.exe into the batch file, as well. The make file should be saved in the same place as the .BAT file we created above, and with a name ending in .MAK ; this name is also substituted into the batch file. To compile the project, just double-click the batch file. Presto!

Further Reading


The copyright of the article The Borland Win32 Compiler Guide in Computer Programming is owned by Guy Lecky-Thompson. Permission to republish The Borland Win32 Compiler Guide must be granted by the author in writing.




Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo