Build System
FiveWin applications follow a multi-stage build pipeline: Harbour compiles your .prg
source into C code, the C compiler produces object files, and the linker assembles the final
.exe. FWH provides several build tools to automate this process.
Build Pipeline
Understanding the build stages helps you diagnose errors. Each stage can fail independently, and the error messages differ between Harbour, the C compiler, and the linker.
Harbour Source"] -->|"harbour.exe
-n -w"| C[".c
Generated C"] C -->|"bcc32 / cl / gcc
compile"| OBJ[".obj
Object File"] RES[".rc
Resource Script"] -->|"brc32 / rc
compile"| RESO[".res
Resource"] OBJ -->|"ilink32 / link / gcc
link"| EXE[".exe
Application"] RESO --> EXE LIB["FiveWin .lib
Harbour .lib
C runtime .lib"] --> EXE
Stage 1: Harbour Compilation
The Harbour compiler reads .prg files and produces .c files.
Typical flags:
harbour myapp.prg -i%FWH%\include -i%HARBOURDIR%\include -n -w -es2
| Flag | Purpose |
|---|---|
-n | Do not generate automatic startup procedure |
-w | Enable warnings |
-es2 | Stop on errors (exit status 2) |
-i<path> | Add include search path |
-d<define> | Define preprocessor symbol |
Stage 2: C Compilation
The generated .c file is compiled by your C compiler into an object file.
Each compiler has different flags; the FWH build scripts handle this automatically.
Stage 3: Linking
The linker combines your object file with the FiveWin library, Harbour runtime libraries, Windows system libraries, and any resource files to produce the final executable.
Using build_new.bat
The build_new.bat script is the recommended universal build tool. It handles
all compiler variants with a single syntax:
build_new.bat <source.prg> <compiler_id>
Compiler IDs
| ID | Harbour | C Compiler | Architecture | Library Used |
|---|---|---|---|---|
hb32 |
Harbour | BCC 5.x (Borland) | 32-bit | FiveH32.lib |
hm32 |
Harbour | MSVC | 32-bit | FiveHM32.lib |
hm64 |
Harbour | MSVC | 64-bit | FiveH64.lib |
hg32 |
Harbour | MinGW GCC | 32-bit | FiveHG32.lib |
hg64 |
Harbour | MinGW GCC | 64-bit | FiveHG64.lib |
xb32 |
xHarbour | BCC 5.x (Borland) | 32-bit | FiveHx.lib |
xm64 |
xHarbour | MSVC | 64-bit | FiveHx64.lib |
Build Examples
// Build with Borland BCC32 (classic, most common):
build_new.bat myapp.prg hb32
// Build with MSVC 64-bit (recommended for new projects):
build_new.bat myapp.prg hm64
// Build with GCC 64-bit:
build_new.bat myapp.prg hg64
// Build with xHarbour + BCC32:
build_new.bat myapp.prg xb32
Detailed Build Flow
This diagram shows exactly what build_new.bat does internally for a BCC32 build:
Using hbmk2 with .hbp Files
For more complex projects with multiple source files, the Harbour build tool
hbmk2 provides a project-file-based workflow. Create a .hbp
(Harbour Project) file to define your build:
Example: test.hbp
# test.hbp - Harbour project file for FiveWin app
# Compiler settings
-gui
-mt
-w3
-es2
# Include paths
-inc
-i${FWH}/include
# FiveWin library
-l${FWH}/lib/FiveH64
# Harbour libraries
-lhbrtl
-lhbvm
-lhbmacro
-lhblang
-lhbrdd
-lrddntx
-lrddcdx
-lrddfpt
-lhbsix
-lhbct
-lhbwin
-lhbcpage
# Windows system libraries
-luser32
-lgdi32
-lcomdlg32
-lwinspool
-lcomctl32
-ladvapi32
-lshell32
-lole32
-loleaut32
-luuid
-lws2_32
-lwinmm
-lmpr
-lmsimg32
# Source files
test.prg
module1.prg
module2.prg
# Resource file
test.rc
Then build with a single command:
hbmk2 test.hbp
The hbmk2 tool automatically detects the installed C compiler, compiles
all .prg files, compiles C code, links everything, and handles incremental
builds (only recompiles changed files).
Useful hbmk2 Flags
| Flag | Purpose |
|---|---|
-gui | Build as a GUI (Windows) application, not console |
-mt | Enable multi-threading support |
-w3 | Maximum warning level |
-es2 | Stop on any error |
-inc | Enable incremental builds |
-rebuild | Force full rebuild |
-comp=msvc64 | Force specific compiler |
-trace | Show commands being executed |
Library Naming Convention
FiveWin libraries follow a naming convention that encodes the Harbour variant and compiler:
| Library File | Harbour | Compiler | Bits |
|---|---|---|---|
FiveH32.lib | Harbour | BCC 5.x | 32 |
FiveHM32.lib | Harbour | MSVC | 32 |
FiveH64.lib | Harbour | MSVC | 64 |
FiveHG32.lib | Harbour | GCC / MinGW | 32 |
FiveHG64.lib | Harbour | GCC / MinGW-w64 | 64 |
FiveHx.lib | xHarbour | BCC 5.x | 32 |
FiveHx64.lib | xHarbour | MSVC | 64 |
Compiler Paths Reference
Default paths used by FiveWin build scripts. Override these via environment variables if your installation differs:
| Variable | Default Path | Contains |
|---|---|---|
BCCDIR |
C:\BCC55 |
BCC 5.x binaries, lib, include |
VCDIR |
C:\Program Files\Microsoft Visual Studio\2022\Community\VC |
MSVC compiler (cl.exe, link.exe) |
MINGWDIR |
C:\mingw64 |
MinGW GCC binaries, lib, include |
HARBOURDIR |
C:\harbour |
Harbour compiler, runtime libraries |
FWH |
C:\FWH |
FiveWin root: include, lib, source, samples |
Multi-File Projects
Real applications consist of multiple .prg files. There are two main approaches:
Approach 1: Batch Script
Compile each file individually and link them together:
// compile.bat - Multi-file build with BCC32
harbour main.prg -i%FWH%\include -i%HARBOURDIR%\include -n -w
harbour customers.prg -i%FWH%\include -i%HARBOURDIR%\include -n -w
harbour reports.prg -i%FWH%\include -i%HARBOURDIR%\include -n -w
bcc32 -c -O2 main.c customers.c reports.c
ilink32 -Gn -aa -Tpe c0w32.obj main.obj customers.obj reports.obj, ^
myapp.exe,, FiveH32.lib harbour.lib cw32.lib import32.lib,, myapp.res
Approach 2: hbmk2 Project File
The simpler and recommended approach for multi-file projects. List all .prg files
in the .hbp file and let hbmk2 manage the build:
# myapp.hbp
-gui
-mt
-w3
-es2
-inc
-i${FWH}/include
-l${FWH}/lib/FiveH64
main.prg
customers.prg
reports.prg
utils.prg
myapp.rc
hbmk2 myapp.hbp
Resource Files (.rc)
Windows resource files define icons, bitmaps, dialogs, and string tables that are embedded in the executable. FiveWin applications typically have at least a resource file for the application icon:
// myapp.rc - Minimal resource file
#include "FiveWin.rc"
APPICON ICON "myapp.ico"
For applications that define dialogs in resource files (rather than creating them at runtime),
you can use the FiveWin Visual Designer (visual/visualfw.exe) to create
.rc files graphically.
Build Tips
- Always clean before switching compilers — object files from one compiler
are incompatible with another. Delete all
.obj,.c(generated), and.resfiles before switching. - Use
-wflag — Harbour warnings help catch undeclared variables and typos early. - Check the .ppo file — When a command does not work as expected, examine
the preprocessor output (
.ppo) to see how FiveWin commands expand. - 64-bit considerations — When building for 64-bit, ensure all libraries (FiveWin, Harbour, third-party) are also 64-bit. Mixing 32-bit and 64-bit libraries will cause linker errors.
- Incremental builds with hbmk2 — The
-incflag skips recompilation of unchanged files, significantly speeding up builds.
Next Steps
- Framework Overview — Learn about FiveWin architecture and class hierarchy
- Installation — Set up your development environment
- TWindow — Start building with the base window class
- TXBrowse — Build data grids for your applications