fbc command-line
- Source: https://www.freebasic.net/wiki/wikka.php?wakka=CompilerCmdLine
- Last revised: 2025-04-07
Using the fbc command-line.
The official FreeBASIC distribution comes with fbc, FreeBASIC's flagship compiler. fbc is a command line compiler, and can be launched from the console - from DOS, the Windows command prompt or a Linux shell. Running fbc from the console without any arguments displays a list of available options, or command-line switches, that can be used to adjust the behavior of the compiler.
At its simplest, fbc takes a source file as a command-line argument and produces an executable file. It does this by compiling the source file (.bas) into an assembly (.asm) file, then compiling this into an object file (.o) using GAS and finally linking using LD this object file to other object files and libraries it needs to run, producing the final executable file. The assembly and compiled object files are deleted at this point by default. For example, the following command,
fbc foo.bas
produces the executable foo.exe in DOS and Windows, and ./foo in Linux. fbc can accept multiple source files at once, compile and link them all into one executable. For example, the following command,
fbc foo.bas bar.bas baz.bas
produces the executable foo.exe in DOS and Windows, and ./foo in Linux. Since foo.bas was listed first, it will be the main entry point into the executable, and also provide its name. To specify a different entry point or executable name, use the "-m" and "-x" switches, respectively. To have, for example, baz.bas provide the main entry point into an executable called foobar.exe, you would use
fbc -x foobar.exe -m baz foo.bas bar.bas baz.bas
The "-x" switch names the executable verbatim, so in Linux, the executable produced from the above command would be called ./foobar.exe.
Syntax
fbc [ options ] [ input_list ]
Where input_list is a list of filenames. Accepted files are:
| File extension | Description |
|---|---|
| .bas | FreeBASIC source file |
| .a | Library |
| .o | Object file |
| .rc | Resource script (Windows only) |
| .res | Compiled resource (Windows only) |
| .xpm | X icon pixmap (Linux only) |
Source code
Add a source file to compilation
Add a path to search for include files
Include a header file on each source compiled
Add a preprocessor's define
Select language mode: fb, fblite, qb, deprecated
Select language mode: fb, fblite, qb, deprecated (overrides statements in code)
Code generation
Set the target platform for cross compilation
Sets the compiler backend (default is 'gas' for x86 and 'gcc' for x86_64)
Sets the assembler format for Asm block
Set target architecture
Set the optimization level (-gen gcc)
Set level of vector optimizations enabled by the compiler (default: 0)
Set the floating point arithmetics unit (default: X87)
Select between fast and accurate floating-point operations (default: PRECISE)
Sets miscellaneous or experimental options
Generate position-independent code (non-x86 Unix shared libs)
Compilation
Define main file (without extension), the entry point (default is the first .bas file on the command line)
Override public exported name of implicit user main function
Add debug info
Enable function profiling by selecting a specific profiler
Enable function profiling for gmon/gprof
Add error checking
Add error checking with RESUME support
Same as -ex, plus array bounds and dimensions, null-pointer, and error location reporting
Enable stack unwind information
Pass options to GAS (separated by commas)
Pass options to GCC (separated by commas)
Set object file path/name (must be passed after the .bas file)
Enable array bounds checking
Enable array dimensions checking
Enable assert() and assertwarn() checking
Enable __FB_DEBUG__
Add debug information
Enable full error location reporting
Enable null-pointer checking
Linking
Add an object file to linker's list
Add a library file to linker's list
Add a path to search for libraries
Link with thread-safe runtime library
Do not include the default libraries
Do not include specific library(s)
Prefer static libraries over dynamic ones when linking
Save the linking map to file name
Pass options to LD (separated by commas)
Export symbols for dynamic linkage
Create a static library
Create a DLL, including the import library
Create a DLL, including the import library. (Same as -dylib)
Set executable/library path/name
Do not strip symbol information from the output file
Omit all symbol information from the output file
Tell the linker where to find libraries (needed by some toolchains)
Behaviour
Set the compiler prefix path
Set the internal buildprefix option
Show compiler version on the command line, do not compile or link
Be verbose
Display certain information (fblibdir, host, target, x)
Emit the preprocessed input file only, do not compile
Compile into intermediate file(s) only, do not assemble or link
Compile into asm file(s) only, do not assemble or link
Compile and assemble source file only, do not link
Do not delete the intermediate file(s)
Do not delete the asm file(s)
Do not delete the object file(s)
Set min warning level: all, none, param, escape, pedantic, next, funcptr, constness, suffix, error, upcast or a value
Only stop parsing if <val> errors occurred
Do not show source line where error occurred
Do not read/write compile-time info from/to .o and .a files
Display a tree of file names of #included files
Target specific
Set subsystem (gui, console)
Set stack size in kbytes (default: 1 MB or 2 MB)
Meta
Read (additional) command-line options from a file
Examples
fbc myfile.bas
(With DOS version of FBC, compile and link a DOS executable MYFILE.EXE.)
fbc -s gui myfile.bas
(With Windows version of FBC, compile and link a Windows executable myfile.exe. Running the program will not show the console window ("MS-DOS Prompt"))
fbc -lib module1.bas module2.bas module3.bas -x libmylib.a
(Compile and link a static library libmylib.a from the three source files)
fbc -m main_module -c main_module.bas
(Compile an object file main_module.o and mark it as an entry point)
fbc -c sub_module.bas
(Compile an object file sub_module.o)
fbc -x application.exe main_module.o sub_module.o
(Link an executable application.exe)
Note: How to include an icon in a FB executable program
There is a simple command line option to compile a FB program into an executable with an Icon:
- Create a *.rc file, for example appicon.rc, with this info:
FB_PROGRAM_ICON ICON "appicon.ico"
(where appicon.ico is the name of icon)
- Then when compiling program, add appicon.rc in the list of files to compile.
See also
Back to DocToc