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.

flowchart LR PRG[".prg
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
FlagPurpose
-nDo not generate automatic startup procedure
-wEnable warnings
-es2Stop 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.

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:

sequenceDiagram participant User participant Script as build_new.bat participant HRB as Harbour Compiler participant BCC as BCC32 (C Compiler) participant BRC as BRC32 (Resource Compiler) participant LNK as ILink32 (Linker) User->>Script: build_new.bat myapp.prg hb32 Script->>Script: Detect compiler paths Script->>Script: Set include/lib paths Script->>HRB: harbour myapp.prg -n -w -i... HRB-->>Script: myapp.c Script->>BCC: bcc32 -c -O2 myapp.c BCC-->>Script: myapp.obj alt Has .rc file Script->>BRC: brc32 -r myapp.rc BRC-->>Script: myapp.res end Script->>LNK: ilink32 myapp.obj + FiveH32.lib + harbour.lib ... LNK-->>Script: myapp.exe Script-->>User: Build complete!

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

FlagPurpose
-guiBuild as a GUI (Windows) application, not console
-mtEnable multi-threading support
-w3Maximum warning level
-es2Stop on any error
-incEnable incremental builds
-rebuildForce full rebuild
-comp=msvc64Force specific compiler
-traceShow 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.libHarbourBCC 5.x32
FiveHM32.libHarbourMSVC32
FiveH64.libHarbourMSVC64
FiveHG32.libHarbourGCC / MinGW32
FiveHG64.libHarbourGCC / MinGW-w6464
FiveHx.libxHarbourBCC 5.x32
FiveHx64.libxHarbourMSVC64

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

Next Steps