ZetCode

Introduction to FreeBasic

Last modified October 18, 2026

FreeBasic is a free, open-source, compiled programming language. It is a modern successor to the classic BASIC language and is designed to be easy to read while still supporting professional features such as object-oriented programming, pointers, and direct access to the operating system's APIs.

FreeBasic

FreeBasic compiles source code into native executables. It produces programs that run without an interpreter or a runtime, which makes deployment simple: a compiled program is a single file. FreeBasic runs on Windows, Linux, and other platforms, and it can link against C libraries.

FreeBasic supports several dialects selected with the -lang option. The default dialect, fb, is the one used throughout this site. Some older keywords and syntax are only available in the qb, fblite, or deprecated dialects.

Installation

The FreeBasic compiler is called fbc. Binary packages for Linux and Windows are available from the official FreeBasic website. After the installation, check that the compiler is available and print its version:

$ fbc -version
FreeBASIC Compiler - Version 1.10.1 (2023-12-24), built for linux-x86_64 (64bit)

On Windows, download the installer or the zip package from the FreeBasic website and add the directory containing fbc.exe to the PATH variable.

The fbc compiler

We compile a source file with fbc and run the resulting program. The -lang fb option selects the default dialect explicitly.

command description
fbc -lang fb hello.bas compiles hello.bas into an executable named hello
fbc -lang fb -w all hello.bas compiles and reports all warnings
fbc -lang fb -c hello.bas compiles to an object file only, without linking
fbc -version prints the compiler version

First example

We create a source file called hello.bas. The .bas extension is used for FreeBasic source files.

hello.bas
Print "FreeBASIC first example"

The Print statement writes text to the console. The program consists of a single statement; no main function is needed. The statements of a program are executed from top to bottom.

$ fbc -lang fb hello.bas
$ ./hello
FreeBASIC first example

We compile the program with fbc and run the executable. On Windows the executable is called hello.exe.

Compiler messages

The compiler reports errors with the file name, the line number, and a message. Fixing the first error often resolves the ones that follow it. For example, using a reserved word as a variable name produces a Duplicated definition error:

error.bas
Dim name As String = "Lucy"
$ fbc -lang fb error.bas
error.bas(1) error 4: Duplicated definition, found 'name' in 'Dim name As String = "Lucy"'

The word name is reserved in FreeBasic, so it cannot be used as a variable name. The next article explains identifiers and the reserved words in detail.

Where to go next

The next article, FreeBasic basics, covers identifiers, variables, types, conditionals, loops, procedures, and arrays. The individual keyword articles describe each statement in more depth.

Source

The official FreeBASIC documentation and wiki at freebasic.net.

Author

My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.

List all FreeBasic Tutorials.