Harbour - step by step

Alexander Kresin
2013

Introduction

Here I will tell you how to install Harbour, how to write and compile your first program - first console, and then the GUI. Perhaps you've looked at the section Harbour for beginners - the same material, in fact, but here is an another form of presentation. I will try to to guide you through one of ways of creation of the program consistently, step by step, not being distracted by the alternatives. Then, once you become familiar with this version and feel confident, you can try to do it differently, Harbour for beginners will help you in it.

The latest official Harbour version - 3.0. It is quite old, so I recommend to use current 3.2 version, the distributions of 3.2 are available as nightly builds.

Prepare to run the compilation from the console; in fact, Harbour - is a console compiler and the language Harbour, like its predecessor, Clipper, in its "pure" form (without additional 3-rd party libraries) is designed for console programs. You may also use for this the standard Windows application Command line in Start\All programs\Accessories (this is for Windows XP) but the best option - is, of course, Far manager - the best program for Windows of all times :), especially if you set all the necessary plug-ins.

So, let's go !

1. Download and install Harbour

Go to the harbour.github.io and download the Nightly binary (Win) build in 7Z or exe format.

Extract the downloaded file on the disk c: (it is possible to extract it in any other place, but for the sake of clarity, we will take the c:), as a result of which we will have there a new directory c:\hb32 (32 in the name of the directory is a number of a current version at the moment of writing this article - 3.2).

Harbour is installed and ready to use. Together with it you have now installed the C compiler - Mingw, it is located in the directory c:\hb32\comp\mingw, it will be used to compile programs.

2. Compile console programs

Many examples - small programs that demonstrate different Harbour's commands and functions, are located in the directory c:\hb32\tests, we'll start with them.

For the beginning we need to create a command file for launching Harbour's make-utility hbmk2, it is necessary to specify in it the path to the Harbour's binaries and to Mingw. In fact, this can be done by setting the environment variables through the Windows My computer/Properties, but here we follow the other way. If you took advantage of my advice, and set Far manager, then you can use it to create the command file, but if not - it can be done, for example, with the help of Notepad. Save this file, call it bldh.bat, preferably in the directory with the programs, which you will compile, in our case - in c:\hb32\tests. So, our bldh.bat contains only two lines:

 
     set path=c:\hb32\bin;c:\hb32\comp\mingw\bin
     hbmk2 %1
   
the first sets the path to the Harbour and to Mingw, the second - launches hbmk2 with the option, with which you will run bldh.bat - with the name of the compiled file.

Now everything is ready to compile. Go to the directory c:\hb32\tests and start the execution of bldh.bat with the prg name that you want to compile, for example:

 
     c:
     cd \hb32\tests
     bldh.bat ac_test.prg
   

It will look something like this:

As a result, you will get a file ac_test.exe - the first program compiled by you with Harbour.

3. Compile a GUI program

As I already mentioned, the Harbour in its pure form creates console programs. To implement graphical interface we have to set one of GUI libraries and we, of course, choose HwGUI.

Download zip-archive with binaries HwGUI for Mingw and unpack it, for example, in c:\hb32 - in any other place is also possible, but for the certainty we'll consider, that it is here. Thus, we have a directory c:\hb32\hwgui.

In c:\hb32\hwgui\samples there are more than 50 small example programs and there is a prepared batch file hbmk.bat to compile Harbour+HwGUI programs.

So, go to the c:\hb32\hwgui\samples and run hbmk.bat with the prg name that you want to compile, for example:

     c:
     cd \hb32\hwgui\samples
     hbmk.bat a.prg
   

As a result we get the compiled a.exe.

When in the future you will be compiling your GUI program, which will be located in a different place, just copy there hbmk.bat and replace the line

  set HWG_PATH=..
   
with
  set HWG_PATH=c:\hb32\hwgui
   
i.e. a relative path to the HwGUI with the full.

Comments:       ()       prev.    next.       Add comment
The length of a comment - no more than 4000 characters.
Your name:

Email address:
(not be shown publicly)
 
Input text from an image: