how to download and use borland ˇs free c++ compiler for … · get & use builder 5.5 page 1...

8
Get & Use Builder 5.5 Page 1 of 8 Gerry Donaldson How to Download and Use Borland s Free C++ Compiler For DOS: Builder 5.5 [Gerry Donaldson, Computer Science Teacher, Sir Winston Churchill High School, Calgary, Alberta, Canada] Date of Last Revision: May 3, 2000 Advantages To Using Borland s DOS Compiler, Builder c++ 5.5: 1. It is current! Builder 5.5 for DOS complies with the International Standards Organization (ISO) August, 1998 definition of C++. Virtually all compilers in CBE schools (and other schools around the world) do not comply with this current definition of C++. 2. It is free! Borland (aka Inprise) is giving it away! It is really an update to the Builder C++ 5.0 compiler. 3. It can be easily used without purchasing any other products! How To Get Borland s Free Builder C++ 5.5 For DOS: 1. Get the installation file from Borland s web site by following their directions at: http:/ /www.borland .com/bcpp builder/freecompiler/cppc55step s.html OR Get the installation file from my web site (installed late April, 2000): http://www.donaldson.org/ Go t o the menu in the left frame. Click o n the plus sign [ + ] be side Dev t Environments, then click on plus sign [ + ] beside Compilers, then click on the plus sign [ + ] beside Borland, then click on the link Download Builder 5.5. 2. Run the file that you just downloaded but change the default directory. When prompted, change the Installation folder from c:\Borland\bcc55 to c:\b55 . Later you will have to type the path many times. It is far easier to type c:\b55 than c:\Borland\bcc55!!! 3. You should now have the following directories (and their files) installed on your hard drive!

Upload: tranthu

Post on 28-Mar-2019

240 views

Category:

Documents


0 download

TRANSCRIPT

Get & Use Builder 5.5 Page 1 of 8 Gerry Donaldson

How to Download and Use Borland �sFree C++ Compiler For DOS: Builder 5.5

[Gerry Donaldson, Computer Science Teacher, Sir Winston Churchill High School, Calgary, Alberta, Canada]

Date of Last Revision: May 3, 2000

Advantages To Using Borland �s DOS Compiler, Builder c++ 5.5:

1. It is current! Builder 5.5 for DOS complies with the International Standards Organization(ISO) August, 1998 definition of C++. Virtually all compilers in CBE schools (and otherschools around the world) do not comply with this current definition of C++.

2. It is free! Borland (aka Inprise) is giving it away! It is really an update to the Builder C++5.0 compiler.

3. It can be easily used without purchasing any other products!

How To Get Borland �s Free Builder C++ 5.5 For DOS:

1. Get the installation file from Borland �s web site by following their directions at:

http://www.borland.com/bcppbuilder/freecompiler/cppc55steps.html

OR

Get the installation file from my web site (installed late April, 2000):

http://www.donaldson.org/

Go to the menu in the left frame. Click on the plus sign [ + ] beside Dev � tEnvironments, then click on plus sign [ + ] beside Compilers, then click onthe plus sign [ + ] beside Borland, then click on the link Download Builder 5.5.

2. Run the file that you just downloaded but change the default directory. When prompted,change the � Installation folder � from c:\Borland\bcc55 to c:\b55. Later you will have totype the path many times. It is far easier to type c:\b55 than c:\Borland\bcc55!!!

3. You should now have the following directories (and their files) installed on your hard drive!

Get & Use Builder 5.5 Page 2 of 8 Gerry Donaldson

C:\B55\INCLUDEC:\B55\INCLUDE\SYSC:\B55\INCLUDE\GLC:\B55\INCLUDE\RW

C:\B55\BINC:\B55\LIB

C:\B55\LIB\PSDKC:\B55\EXAMPLES\STDLIB

C:\B55\HELP

Create, Compile and Run C++ Programs Using Builder 5.5 for DOS

The following instructions are tailored to a PC environment running under Windows NT or95/98/2000. It assumes access to the DOS shell and a text editor. It assumes that source codeis saved in the directory c:\source and that object and executable code is saved in c:\output.

When in Rome, do as the Romans do. When in DOS, use the tools of DOS. Most studentstoday are used to working exclusively in the Windows 95/98 graphical interface. It is possible todo much of the following in that interface, but some of it (the compiling) must be done in theDOS shell. Rather than moving back and forth between environments, I encourage students toget comfortable with working exclusively in the DOS shell as well as working exclusively ingraphical interface. For that reason, I aim of the following instructions towards workingexclusively in the DOS shell. Ultimately though, each student will decide for themselves wheretheir comfort level is, and that is fine with me.

I give detailed, key stroke by key stroke, directions below together with explanations. Students should make their own notes while creating directories and working the examples. Students should then make abbreviated notes on an index card that makes sense to them.

I give this high level of detail in the first instance because it is so easy to miss one simplekeystroke and then nothing works at all. I would rather that students take the apparentlyextra time (usually a saving of time) and experience success rather than whiz through abbreviatednotes, make simple errors that nevertheless prevent anything from happening, and then experienceunnecessary frustrat ion when the process fails to work properly.

1. Value a CMI environment like DOS. Windows is fine, but DOS still has its place!

Have a positive attitude and all goes well. Be a �DO-BEE � , not a � DON �T-BE � !

DOS is a Command Line Interface [CMI]. You give commands by typing on a line.

Windows is a Graphical User �s Interface [GUI]. You give commands by clicking on icons.

Get & Use Builder 5.5 Page 3 of 8 Gerry Donaldson

A hammer may be better for pounding nails, but a saw is better for

cutting wood. Prefer the tool for a job that better does that job.

DOS DOES SOME JOBS BETTER THAN WINDOWS!

2. Create a directory to store your files of C++ source code. Create the directory: c:\source

Do this in Windows if you prefer. The following directions do it in the DOS shell.

a) Leave windows and go into the DOS shell: Start | Programs | MS-DOS Prompt

b) Go to the root directory of your C: drive. After the prompt, type: cd \

This means � change directory to the root directory. � The backslash [ \ ] is the DOSsymbol for the root directory. You should now have a prompt that looks like this: c:\>

c) The DOS command, md, is used to make a directory. The letters stand for � makedirectory. � The symbol !µ represents a carriage return. Press Enter when you see it.

Following the prompt, c:\>, type the command to create the directory for your sourcecode: c:\> md source!µ

Now all of your source code files (*.cpp and *.h files) may be stored in one directory.

3. Create a directory to store your files of C++ output files. Create the directory: c:\output

Do this in Windows or do to the same thing as above to create your output file in DOS.

Following the prompt, c:\>, type the command to create the directory for your source code: c:\> md output!µ

Now all of your output files (*.tds, *.obj, and *.exe files) may be stored in one directory.

4. Confirm that both source and output directories exist by typing: c:\> dir!µ

5. Create a C++ program using a text editor. Store that program in a text file in yoursource directory. Remember that a C++ program is a text file. Any text editor will do.

You may create your source code with a windows text editor such as Notepad or Wordpad oreven a wordprocessor such as MS-Word or Corel �s WordPerfect. Always be sure to saveyour file as a text file to avoid saving control characters that C++ does not recognize.

Every DOS user should know how to use the EDIT text editor because it came with everyversion of DOS in the past decade. You �ll always � get by � if you know how to use it.

Get & Use Builder 5.5 Page 4 of 8 Gerry Donaldson

To use this DOS text editor, go to any command prompt and type: EDIT. For example:

c:\source\> edit!µ

By way of example, turn to the next page and type the source code for � Hello World � .

#include < iostream .h>

int main( )

{

cout << "Hello World.";

return( );

}

From within the DOS editor (called EDIT) save your file as follows.

Click on File. Then click on Save As ... Type the name in the dialogue box: hello.cpp!µ

You have now saved a text file containing your source code as c:\source\hello.cpp

Note: next time you can both launch the EDIT editor and load your source code into it byadding the name of your source code file after typing EDIT: c:\source\> EDIT hello.cpp!µ

6. Go to the Bin directory holding the �binary files � that work with your compiler.

You must be in this directory when you compile your source code (or place this directory inyour path . .. but more on that at another time) so that the compiler will find other files that itworks with when converting your C++ source code into an executable *.exe type file.

Binary files contain machine language code. Machine language is the language that yourcomputer � understands � when it runs a program. Machine language files are called binaryfiles because machine language is made of patterns of binary digits: zeros (0) and ones (1).

The files in the Bin directory are programs that translate and link your C++ source code intoan executable file ... which usually has an .exe extension. (The .com extension is obsolete.)

Other files are usually data files. These usually contain ASCII symbols such as alphabeticalcharacters (a .. z, A .. Z), decimal characters (0 .. 9) and punctuation characters. These filesare generally referred to as text files. They can be read with a text editor or wordprocessor.

If you are in the Bin directory, your prompt should look like this: c:\b55\Bin\>

Get & Use Builder 5.5 Page 5 of 8 Gerry Donaldson

7. Why use a batch file when compiling in DOS?

A batch file will contain commands that launch the compiler program and tells it when to � switch � to other directories so it can find the source code file, the include files, the libraryfiles, and where to save the output files.

You can type these commands each and every time you compile a file of source code, but thatinvolves an awful lot of typing. If you make a mistake or just want to revise your source codeand compile the new version, it is a real pain to repeatedly retype the commands. That is whywe place the commands in a batch file and simply run the batch file every time we want tocompile our source code.

A batch file is itself a text file that contains all the commands that you would normally type ona command line following a prompt. It has a .bat extension, which is an abbreviation of theword, batch. The commands in a batch file are placed in precisely the same sequence that youwould type them on the command line, and they will be executed in precisely that sequence!

8. Create a batch file in the c:\b55\Bin directory.

Your prompt should look like this if you are in the Bin directory: c:\b55\Bin\>

Launch the text editor EDIT and call the file � hello.bat � Type the following at the prompt:

c:\b55\Bin\> edit hello.bat!µ

Caution: It is easy to incorrectly type the following commands if you just type mechanicallywithout understanding what you are typing. For that reason, I strongly urge you to read thefollowing explanations of each command.

Note: All of the following commands must be typed on the SAME line!

c:\b55\bcc32.exe -Ic:\b55\Include -Lc:\b55\Lib -nc:\output c:\source\hello.cpp

You can shorten the above line a bit by substituting c:\ (which refers to the root directory -denoted by the backslash � \ � character - of the c: drive) with the abbreviated version of thebackslash alone, � \ � . This works because the path will look to the root directory of the drivethat the text file is in, and that happens to be the c: drive.

bcc32 -I\b55\Include -L\b55\Lib -n\output \source\hello.cpp

When finished, save the batch file by calling the File menu (Alt-F) followed by pressing S. Exit the EDIT program by going to the file menu with Alt-F. Then exit by pressing Alt-X.

Get & Use Builder 5.5 Page 6 of 8 Gerry Donaldson

9. Run the batch file at the prompt instead of typing all the files and switches each time.

You can repeatedly type the following command line:

c:\b55\Bin\> c:\b55\bcc32.exe -Ic:\b55\Include -Lc:\b55\Lib -nc:\output c:\source\hello.cpp!µ

OR

You can type the name of the batch file that contains the same command line!

c:\b55\Bin\> hello.bat!µ

10. What do the batch file commands and switches mean and/or do?

bcc32 bcc32.exe is the compiler itself. This is the program that translates thesource code into machine language.

-I\b55\Include Switches begin with a hyphen. The I switch stands for � Include � . Immediately following is the path to the directory that contains files ofsource code that is to be � included � in the program. This particularpath is c:\b55\Include, or rather the abbreviated form: \b55\Include.

-L\b55\Lib Switches begin with a hyphen. The L switch stands for � Library � . Immediately following is the path to the directory containing � standardlibraries � of source code that may be used in the program. Thisparticular path is c:\b55\Lib, or rather the abbreviated form: \b55\Lib.

-n\output Switches begin with a hyphen. The n switch stands for � new � files, theoutput directory where newly created files will be saved. Theseinclude files having the extensions *.tds, *.obj, and *.exe. Thisparticular directory is c:\b55\output, abbreviated as: \b55\output.

\source\hello.cpp This is not a switch. We know so because it does not start with ahyphen. This is the name of the file where the compiler will find thesource code that we want to translate into machine language. Thisparticular path is c:\source\hello.cpp, or rather the abbreviated form: \source\hello.cpp

\output\hello.exe This file is not found in the batch file.

The compiler will read this source code and save the resultingexecutable file in the c:\output directory as hello.exe. This file may becopied to any directory and executed independently of other files.

Get & Use Builder 5.5 Page 7 of 8 Gerry Donaldson

How to Use Borland �s Builder 5.5 for DOSWhen Compiling � Chained � Multiple Files

This is a continuation of the Article How to Download and Use Borland � s Free C++Compiler For DOS: Builder 5.5. This continuation is aimed at senior (Computer Science 2)students who compile programs by chaining multiple files.

The following files are from Chapter 9, � Building Structured Data: Structs and Classes � ,FUNDAMENTALS OF C++: UNDERSTANDING PROGRAMMING AND PROBLEMSOLVING by Kenneth A. Lambert and Douglas A. Nance (South-Western EducationalPublishing, Cincinnati, Ohio) 1998. ISBN: 0-314-20493-8.

Copies of these files that have been successfully compiled under both Turbo C++ 3.0 and Builder5.5 for DOS may be found at Gerry Donaldson �s web site: http://www.donaldson.org Click onthe link, Lambert �s Source Code, found in the middle of the Welcome Page (right frame). Then

click the digit 9 to go to chapter 9. Note that the source code originally provided on disk byLambert and Nance did not compile correctly because of errors in the sequencing of the #includestatements. That sequencing is corrected and will be found as represented in the following table.

Note: Recall the following preprocessor syntax when using #include statements:

1. Angled brackets < > surrounding the name of a file indicate that the file will be found in the � include directory � . Virtually all compilers provide a way to pass the location of thatdirectory to the compiler during the compilation process.

2. Double quotation marks " - - - " surrounding the name of a file indicate that the file will befound in the same directory as the file that calls it with the #include statement.

3. Do not #include bool.h when compiling with a compiler that already supports the boolean datatype. This will usually trigger an error and prevent compilation.

file #include statement(s) directory of file to be included

bankdriv.cpp #include <iostream.h>#include <iomanip.h>#include "account.cpp"

c:\b55\includec:\b55\includesame directory as bankdriv.cpp

account.cpp #include "account.h" same directory as account.cpp

account.h #include "apstring.cpp" same directory as account.h

apstring.cpp #include <st ring.h>#include <assert .h>#include "apstring.h"

c:\b55\includec:\b55\includesame directory as apstring.cpp

apstring.h #include "bool.h" same directory as apstring.hNOTE: Comment out this #include statement if the

compiler already supports bool data types.

bool.h No #include statements bool.h is used when compiling with Turbo C++ 3.0but not with Borland c++ 4.5, 5, 5.02, or Builder!

Get & Use Builder 5.5 Page 8 of 8 Gerry Donaldson

Create A Batch File

Create a batch file that only calls the client program. The client program in turn uses #includestatements to call other files. Other files, as needed, use #include statements to call yet other files.

The following file is the batch file, bank.bat, that gets the ball rolling.

The batch file, bank.bat, initiates the compilation of multiple files beginning with the driverprogram, bankdriv.cpp. The driver bankdriv.cpp will #include account.cpp which, in turn, will#include account.h which, in turn, will #include apstring.cpp which, in turn, will #includeapstring.h. In Turbo C++, apstring.h would #include bool.h. Do not #include bool.h whenusing Borland �s C++ 5.5 compiler as it already supports the bool data type.

Note that you do not include the name of a file in the batch file if that file is #included by way of apreprocessor statement in a further file.

Create a batch file in the c:\b55\Bin directory just as you did for a single file program.

Your prompt should look like this if you are in the Bin directory: c:\b55\Bin\>

Launch the text editor EDIT and call the file � bank.bat � Type the following at the prompt:

c:\b55\Bin\> edit bank.bat!µ

Remember: All of the following commands must be typed on the SAME line!

bcc32 -I\b55\Include -L\b55\Lib -n\output \source\bankdriv.cpp

Run the batch file at the prompt instead of typing all the files and switches each time.

c:\b55\Bin\> bank.bat!µ

Is there an easier way to do all this? Yes. Use an IDE (Integrated Development Environment).

Acknowledgement: The following article by John Thomas provided the necessary guidance toproduce the foregoing article. It was aimed at the experienced programmer, and went muchfurther than the obscure � readme.txt � file that comes with the compiler package. Still, it fellshort for many young students uncomfortable with the � ancient � world of DOS. Yet, it wassufficient for me to bridge the information � priesthood � gap between the package and itsimplementation.

Thomas, John. Using the Borland 5.5 Compiler and Command-Line Tools.(© Borland Community Web Site: March 3, 2000.) Found on the Web Site on May 3,2000: http://community.borland.com/article/0,1410,20997,00.html