Next Previous Contents

4. Getting started

What's needed?

Here is how the compilation process goes:

As you see, getting the executable program from the source code involves two different kind of compilers and a linker.

The good news is that everything is available as open source software, which means that using these softwares is free. The bad news is that they are a little bit awkward to set up.

4.1 Getting started on Windows

MiniGUI

The easiest way to get started on Windows is to use MiniGUI.

Download the file "hmg20_020.exe" from the link at http://sourceforge.net/projects/harbourminigui/

Harbour MiniGUI 2.0

http://www.geocities.com/harbour_minigui

http://harbourminigui.googlepages.com

This is the hellow.prg (a Win32 application):

#include "minigui.ch"
Function Main
DEFINE WINDOW Win_1 ;
AT 0,0 ;
WIDTH 400 ;
HEIGHT 200 ;
TITLE 'Tutor 01 - Hello World!' ;
MAIN
END WINDOW
ACTIVATE WINDOW Win_1
Return

And then you set the variables and call the batch compiler:

set HB_ARCHITECTURE=w32
set HB_COMPILER=mingw32
set HB_BIN_INSTALL=c:\xharbour\bin
set HB_LIB_INSTALL=c:\xharbour\lib
set HB_INC_INSTALL=c:\xharbour\include

set Path=C:\hmg\MINGW\bin;C:\hmg\BATCH;

compile hellow

And the compilation of the standard helloworld program is done through

compile hello /c

where the option /c specifies it is a console application.

Getting Started with Harbour 0.99.3 and the Borland C++ Compiler 5.5

If  for example we use Windows and have decided to go for Borland C++ 5.5, we must first set it up and then we must set up the cross-compiler. MiniGUI simplified the process losing a (large) bit of flexibility, that's anyway good if you were to get started quickly.

There is a "Borland C++ 5.5 tutorial" at http://www.webnotes.org/bcc55eng.htm. Other informations are on "C/C++ Programming using the free Borland® C++ 5.5 Compiler, Linker and Turbo™ Debugger" at http://mirror.href.com/thestarman/C/bcpp55.html.

Getting started with Harbour is easier, because it comes with a script, bld, that automates the compilation process from the command line. xHarbour is not user-friendly as Harbour is, and I still do not know exactly the differences between the two. As xHarbour is also a bigger download, I suggest that you download Harbour.

As the first example, we will install Harbour with the Borland C++ Compiler. We must start installing the Borland C++ Compiler.

Follow these steps (they are copied almost verbatim from the readme of the package):

1. Run freecommandlinetools.exe; choose the drive and folder into which you want to install the free C++Builder 5 command line tool development system. (The best choice is to install it in c:\Borland\Bcc55, the default directory).

In the bin directory of your installation:

2. Create a bcc32.cfg file which will set the compiler options for the Include and Lib paths (-I and -L switches to compiler) by adding these lines:

-Ic:\Borland\Bcc55\include
-Lc:\Borland\Bcc55\lib

3. Create an ilink32.cfg file which will set the linker option for the Lib path by adding this line:

-Lc:\Borland\Bcc55\lib

Now you should set the PATH variable so that your Command Prompt finds the compiler bcc32 and the linker ilink32:

1. Using your mouse, right-click on My Computer (the Desktop icon) and choose "Properties".
2. In the window that pops up, click on the "Advanced" tab.
3. Click on "Environment Variables..." (the middle button).
4. Under "System Variables" (the bottom box) look for and then click on (highlight) the Variable, "Path":
5. Click on the "Edit..." button:
6. So, carefully append ;C:\BC55\BIN (don't forget the semicolon) to the end of this line of pathways!
7. Click OK in this window ("Edit System Variable").
8. Click OK in the "Environment Variables" window.
9. Click OK in the "System Properties" window. If you don't click OK on all of these, the PATH variable may not be changed.

After you've installed the Borland C++ Compiler, I suggest that you verify it, so that you are sure it works correctly. It is very easy. You should simply key in the helloworld application in C++ and compile it with the command "bcc32 hello.cpp" from a Command Prompt.

The helloworld source (copy this in the hello.cpp file) is this:

#include <iostream.h>

main()
{
cout << "Hello, the weather is fine today";
return 0;
}

Try running it by calling the executable hello.
If it does not work, you didn't install correctly the BCC and you should check where is the problem. Try again the steps above.

If it works, extract the file harbour-0.99.3.bin.w32.bcc32.zip in c:\. (Be sure to have the ZIP file that goes with the compiler you're using, or the linker will have problems).

Now we must set up a few variables to be able to run bld. It is a batch file, that uses informations stored in system variables to guide harbour and bcc to get the executable. Key in this:

set HB_ARCHITECTURE=w32
set HB_COMPILER=bcc32

Now when you run bld it will know that it is running under Windows (w32 architecture) and that it is using the Borland C++ Compiler (bcc32 compiler).

You need to set also these three variables:

set HB_BIN_INSTALL=c:\harbour\bin
set HB_LIB_INSTALL=c:\harbour\lib
set HB_INC_INSTALL=c:\harbour\include

Put the lines in your AUTOEXEC.BAT file (if you are using a Windows 9x or ME) or set the variables as we've done above so that you've them set up automatically at startup. I update also the path, adding ";c:\harbour\bin" at the end of the line.

Now we can try our harbour. Key in the helloworld application:

function MAIN
? "Hello, the weather is fine today"
return

Save it in the file hello.prg and compile it using the command "bld hello". Try running it by calling the executable hello.

Here is a screenshot that should clarify how much the variables count when you're using open source xBase implementations under Windows.

If you read the next section, you will find another proof that they are very important.

Note: as you can see, both the programs have something named main inside and return something. You'll see later what main means and what returning involves.

There is another file that describes how to get started with Harbour, http://gnosis.cx/publish/programming/harbour.html.

Getting started with xHarbour using MinGW

http://www.mingw.org/docs.shtml. See the MinGW Starter Guide at http://www.spacejack.org/games/mingw/.
The easiest way to get a working MinGW compiler is to download Bloodshed Dev-C++ from http://www.bloodshed.net/devcpp.html. This is a C++ IDE and here we see the flexibility of Harbour and xHarbour compared to MiniGUI: we can use the compiler provided with that IDE without any problem, while this can be done with MiniGUI only by changing by hand many text files.

We'll use devcpp-4.9.9.2_setup.exe.

Uncompress in C:\xharbour the file xharbour-0.99.70.bin.w32.mingw32.zip.

Now set the variables:

set HB_ARCHITECTURE=w32
set HB_COMPILER=mingw32
set HB_BIN_INSTALL=c:\xharbour\bin
set HB_LIB_INSTALL=c:\xharbour\lib
set HB_INC_INSTALL=c:\xharbour\include

This time, of course, the path will be different, as follows in the screenshot:

Now you must remember that you should download the correct harbour file for the compiler you wish to use, or you'll get an error such as this:

c:\harbour\lib\codepage.lib: file not recognized: File format not recognized
collect2: ld returned 1 exit status

It is, you see, and error returned by ld, the MinGW linker.

It is important to have the correct pair of (x)harbour/C++ compiler or the linker won't work and you won't get any executable file.

Check if it works by running:

xbscript hello

Does xHarbour greet you?

4.2 Getting started on Linux

In this section we download the sources and build the cross-compilers using GCC.

Clip 1.2.0

http://www.itk.ru/english/index.shtml

# tar xzf clip-prg-1.2.0-0.tgz 
# cd clip-prg-1.2.0-0
# ./make system
# cat > hello.prg
# clip -esln hello.prg 
# ./hello

Clip contains many features: Oracle, Postgres, MySql, bzip2, zlib, GTK support, and gd 1.8.4 (a graphics library for fast image creation)

It will be installed by default in the directory /usr/local/clip/, and some documentation will be in /usr/local/clip/doc/. I suggest that you look at the examples, that are surprizing.

First of all, we must uncompress the tgz.
# tar xvzf clip-prg-1.1.10-1.tgz

The installation is done by a Makefile and the target name is system:
# make system

Let us now try the hello.prg:

Function Main
? "Hello"
?
Return

Compile it by
# clip -esln hello.prg
and run it:
# ./hello

The following picture shows you how the test of helloworld might look in a single screenshot:

Harbour 0.99.3

http://www.harbour-project.org/

# tar xvzf harbour-0.99.3.src.tar.gz 

xHarbour 0.99.70

http://www.xharbour.org/

# cd xharbour-?0.99.70
# ./xharbour-0.99.70-linux_2.4.26.inst.sh 
# xhbmk hello.prg
# ./hello 

4.3 Another compiler: x2c


Next Previous Contents
Hosted by www.Geocities.ws

1