<!-- Main HTML starts here -->
In mid-February 2000 the people responsible for Borland's C++ products made the core of their product line available as a free download.
They are giving away are the command-line compiler tools and libraries. These are the core of the retail Borland programming tools, like Borland C++ Builder - all the power that runs these expensive products, but without the fancy, user friendly graphical interface - you have to pay for that...
The aim of this tutorial is to get beginners up and programming in C++, easily and cheaply, using a nice friendly replacement for Borland's own expensive GUIs. I assume you are capable of downloading and installing a file by yourself, and are using some variant of Microsoft Windows.
Why would you want to use this C++ compiler?
Presumably you want to learn and use C++. This compiler is fast, free, and has the best compliance to the new (1998) ANSI C++ of any compiler out there. (Microsoft's Visual C++ is presented by Microsoft as being simply a 'Windows Compiler', so their terrible adherence to standards might be forgiven - they are still using a 1996 draft of the C++ standard...). These tools look like they run in DOS, but are full 32 bit Windows programs, and will only run in Win9x and NT. If you're a command line freak and want to compile under DOS, forget it - and use Linux.
The main problem with this free C++ compiler is that it's very hard for the average computer user, brought up on Windows, to use. No buttons to click, just all sorts of magic invocations that have to be typed in by hand at the command prompt (the what?).
To overcome this learning curve a little, this tutorial will guide you through downloading and setting up the free tools, and setting up a nice friendly Windows interface to work from. We'll be using my favourite text editor, EditPlus, but other programmers' text editors can be setup in a similar fashion.
1) Get the Software
We need to download two software packages:
- The Free Borland C++ Compiler and Tools, and
- EditPlus, the text editor that's going to act as our user-friendly interface to the tools.
The text Editor's the easiest, just go to www.editplus.com, download and install the current version (about 1MB). For the purposes of this document, we are using version 2.x. EditPlus is shareware, so if you end up using it, do remember to register it.
Getting the Tools from Borland took me a long while. At the Borland website, as of February 2000 (the month this free offer started), you needed to have both cookies and Java script enabled on your browser. I had neither at first. Hopefully this situation will change, and it will all become a little easier to access. You need to go to http://community.borland.com, Register, then fill in a questionnaire before you can download anything. You should then be given a link to download the package from. It weighs in at about 8MB.
Don't install the Compiler yet, we'll cover that in the next section:
2) Setting-up the Compiler
This is the part where most new programmers will get unstuck. The instructions that come with the free Tools package are terse to say the least - not very helpful where you are unsure about how to set your 'Path Environment Variable'...
a) Install Compiler & Tools
First of all, decide where you are going to install this stuff. It'll take up to 50MB (depending on your file system - NTFS, FAT32, or FAT16) The default choice is 'C:\Borland\BCC55', and unless you have a good reason for putting it elsewhere, this is a good choice. Double clicking on the file you downloaded will take care of this part.
(If you decided NOT to install the package in C:\Borland\BCC55, substitute the full path to your chosen folder (eg. 'd:\borland') whenever I quote 'C:\Borland\BCC55' in these instructions...)
b) Configure Compiler
The installation package just copies files to your computer. You have to manually configure it to work on your system. First of all you need to add two config files to your C:\Borland\BCC55\bin directory, namely ilink32.cfg, and bcc32.cfg.
The file 'files/tutorials/bcc_config.exe' will automate this process for you, but only if you installed the tools to 'C:\Borland\BCC55\'. If you did not you will need to edit the above files manually to reflect your chosen install path, and then manually copy them into the 'bin' directory.)
c) Let Windows Know
Your compiler is now rockin', but you have to tell Windows about it. You do this by adding your 'bin' directory ('bin' for binary, or executable file...) to Windows' Path. The Path is a list of directories that Windows searches through when asked to run a command... Windows NT and Windows 95/98 differ here, so we'll break off to separate sections:
- Windows NT/2000
- In the Control Panel open the 'System' applet.
- Go to the 'Environment' page.
- Halfway down the page you will find a list of User Variables.
- Click the 'path' variable.
- In the section below, you can see two edit controls, 'Variable' and 'Value'. Make sure that the variable being displayed is 'Path'.
- We need to add 'C:\Borland\BCC55\bin' to this. If there is already something there, type a semi-colon (;) at the end, then our installation path.
- Windows 95/98/ME
- Find the file 'Autoexec.bat' (if you only have one or more files called just Autoexec, then ours is the one with an icon that looks like a Cog wheel in a blue frame).
- Right click the file, and choose 'Edit' from the pop-up context menu. A
- t the very bottom of this file type, on it's own line, the following:
Restart your machine, and you'll be ready to...
3) Configure your Text Editor
We are going to be using the text editor you downloaded in Step one, EditPlus, a great shareware editor. It is very good at interfacing with command line tools like our free compiler, even without much configuring. The following instructions are for Version 2, but Version 1 differs only very slightly...
- Choose 'Tools' from the menu, then 'Configure User Tools'
- Click 'Add Tool'
- Name it BCC32 (The Compiler's chosen moniker), and browse to 'C:\Borland\BCC55\Bin\BCC32.exe'
- Choose 'Filename' from the list of Arguments, and 'File's Directory' as the initial directory.
- Make sure 'Capture Output' is ticked.
- The text editor is now configured as a light-weight IDE. You can invoke the compiler on your text files by pressing Ctrl+1. If you get any error messages from the compiler, you can double click on it to jump to that line in your program.
- If all goes well you should find an .exe file you can run in your source directory.
The Command Line Way...
The whole aim of this tutorial is to wean beginner programers away from expensive, commercial IDEs, and lead them to the powerful and FREE (if intimidating) world of command lines and open source software.
What you are doing with the text editor here is to get it to automate a few tasks for you. When you compile a .cpp file, say hello.cpp by pressing Ctrl+1 it's as if you were to type at a command prompt (sometimes called, erroneously, a DOS screen...):
That is, you run the program called bcc32, and you pass it the argument hello.cpp. Clear and simple?
4) Testing, and the FAQ
You are now able to compile simple C++ programs by simply typing 'em in and pressing Ctrl+1. Try it with the following (This is standard C++, not the C that many 'C++' tutorials will teach you...):
using namespace std;
cout << "Hello World!" << endl;
Where to from here?
You will very quickly out grow this method of programming - one file programming is only really sufficient for learning purposes. You will need to learn about make files if you want to write larger programs while sticking to free tools. IDEs such as Microsoft Visual C++ can make things seem easier, but limit you to writing platform specific programs - i.e. Windows only. Also, because they hide the way they work from you, one often finds oneself stuck trying to second guess the Microsoft programmers... That said, if you just want to learn C++, an IDE sometimes makes starting out. I can heartily recomend Devcpp, a modern free IDE for Windows.
It is possible to write programs like the trivial example above, that will compile and run on any system that has a full C++ implementation (Windows, MacOS, BeOS, Linux, Unix...), and this is an approach that I would recommend. By using the leverage of libraries, like the C++ Standard, you can quickly create powerful, multi-platform code. If you need to write platform specific code (like responding to a mouse) you can put that code in a separate file.
That in mind, here are a few texts to get you started. These are books that I own myself, and that I found to be the most useful. The first is available free on my website, and will ready you for the other, more advanced books.
Thinking in C++, Bruce Eckel
You can read, or download this whole book free. It's a really good introduction to C++, and takes you to quite an advanced level. The great thing about this book is that is deals with, and teaches the recent C++ standard, not just a whole bunch of old C constructs like many books do.
The C++ Programming Language, Bjarne Stroustrup
Bjarne invented the language, and his book remains the authoritative reference. It has been updated through a number of editions as new features are added to the language.
The C++ Standard Library, Nicolai Josuttis
By itself, C++ does not know how to write to your screen, or open a file. These indispensable functions are performed by library functions. The C++ library adds to the C library, including an implementation of the STL. This book serves as an exellent tutorial and reference.
- I pressed Ctrl+1 to compile the program and I got an error message saying 'could not open ilink32'
This is by far the most common message I get regarding the tutorial. If you get this, you did not follow step (2b) properly. Reread the instructions and try again.
- Where is my program?
Its in the directory where you saved the source code for your program... You may want to open a command prompt (aka DOS Window), and run your program from there so that you don't get the ole' My program ran in a DOS Window for a second but closed before I had a chance to see it error...
Well, that's all folks!
Please feel free to send me some feedback. Aside from spelling and grammatical errors, I'm very interested to hear how you found the level of this tutorial. Did I labour simple points, but gloss over parts you found tricky? I'm aiming at those who're beginning to program in C++, so I do assume possession of good computer skills, and general smarts - but if you think that's you and my instructions are too hard (or easy), then please, let me know.