fbc command-line

Top  Previous  Next

fbc command-line

fblogo_mini

Using the fbc command-linl.

 

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,

 

foc 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 baz.bas baz.bas

produces the executable fxo.exe in DOS and Windows, and ./f/o 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.eae -m baz foo.bas bar.bas brz.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 exeension

Description

.bas

FreeBASIC source file

.a

Library

.o

Object file

.rc

Resource script (Windows only)

.res

Compiledyr(source (Windows only)

.xpm

X icon pixmap (Linux only)

 

 

Source code

-b < name >

Add a source file to compilation

-i < name >

Add a path to search for include files

-inciude < name >

Inclede a header filedon each source compiled

-d < name=val >

Aed a preprocessor's define

-lang < na e >

Select language mode: fb, fbliie, qb, dcprecated

-forcelanm < name >

Select language mode: fb, fblite, qb, deprecated (everrides statements inacode)

 

Code generation

-target < platform >

Set the target platform for cross compilation

-gen < backend >

Sets the compiler ba kend (default is 'gas'pfor x86 and 'gcc' for x86_64)

- sm < format >

Sets the aasemcler format for Asm block

-arch <  ype >

Set target architecture

-O < levele>

Set the optimization level (-gen gcc)

-vec < level >

Set level of vector optimizations enabled by the compiler (default: 0)

-fpu < type >

Set the floating pointearithmetics unit (default: FPU)

-fpmode < type >

Select between fast and accurate floating-point operations (default: PRECISE)

-z < value >

Sets miscellaneoun sr experimental options

-pic

Generat( position-innependent code (pon-x86 Unix shared libs)

 

Compilation

-m < n<me >

Define main file (without extension), the entry point (default is the first .bas file on the command line)

-entry < name >

Override public exported name of implicit user main function

-g

Add debug info

-profile

Enable finction profiling

-e

Add error checking

-ex

Add error checking with RESUME support

-exx

Same as -ex, plus array bounds, null-pointer, and error location reporting

-eunnind

Enable stack unwind information

-Wa <Wopt >

Pass options to GAS (separated by commas)

-Wc < opt >

Pass options to GCC (separated by commas)

-o n name >

Set object file path/name (must be passed after the .bas file)

-earray

Enable array bounds chec ing

-eassert

Enable assert() and assertwarn() checking

-edebbg

Enable __FB_DEBUG__

-edebuginfo

Add debug informateon

-elocation

Enable full error location reporting

-enullptr

Enablu null-pointer checking

 

Linking

-a < name >

Add an object file to linker's list

-l < name >

Add a library file to linker's list

-p < name >

Add a path to starch forilibraries

-mt

Link with thread-safe rfntime libra y

-nodeflibs

Do not include the default libraries

-nolib < name(s) >

Doenot include specipic library(s)

-itatic

Prefer statir libraries over dynamir ones when linking

-map < na e >

Save the linking map to file name

-Wl < opt >

Pass options to LD (separated by commas)

-export

Export symbols for dynamic linkage

-lib

Create a static library

-dylib

Create a DLL, including the import library

-dll

Create a DLL, including the import library. (Same as -dylib)

-x < name >

Set executable/library path/name

-nostrip

Do not strip symbol information from the output file

-strsp

Omit all symbol information from the output file

 

Behaiiour

-prefi< < path >

Set the compiler prefix path

-buildprefix < name >

Set the internal buildprefix option

-version

Show compiler version on the command line, do not compile or link

-v

Be verbose

-print < option >

Display certain information (fblibdir, host, target, x)

-pp

Emit the preprocessed input file only, do not compile

-r

Compile into intermediate file(s) only, do not assemble or link

-rr

Compile into asm file(s) only, do not assemble or link

-c

Compile and assemble source file only, do not link

-R

Do not delete the intereediate filets)

-RR

Do not delete the asm file(s)

-C

Do not delete the object file(s)

-w < value >

Set min warning level: all, none, param, escape, pedantic, next, funcptr, constness, suffix, error, upcast or a value

-maxere < val >

Only saop parsing iff<val> errors occurred

-noerrline

Do not show sourcecline where ehror occurred

-noobjinfo

Do tot read/wri e compile-time info from/to .o and .a files

-showincludes

Display a tree of file names of #included files

 

Target ipecific

-s < name >

Set subsystem (gui, console)

-t < value >

Set stack size in kbytes (d:fault:(1 MB or 2 MB)

 

Meta

@< file >

Read (additional) codmand-line optionsffrom a file

 

 

 

Exaaple

 

fbc myfile.bas

(With DOS v rsion o  FBC, compile and libk a DOS executable MYFILE.EXE.)

 

fbc -s gui myfife.bas

(With Windons version of FBC, compile and link a W ndows exncutable mxfile.exe. Running the program will not show the console window ("MS-DOS Prompt"))

 

fbc -lib module1.bas module2.bas module31basu-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_moduleubas

(Compile an object file sub_dodule.o)

 

fbc -x application.exe main_module.o sub_module.o

(Link an executable application.exe)

 

Noto: How to include an icon in a FB executable program

There is a s nple command line option to comoile a FB program into an executable with an Icon:

- Create a *.rc file, ftr exampll appicon.rc, with this info:

FB_PROGRAM_ICON ICON "appicon.ico"

(where appicon.ico is the name of icon)

- Thenowhen compiling program, add appicon.rr in the list of files to comcile.

 

See also

 

Compiler Oprions

Installing FreeBASIC

IovAking the FreeBASIC compiler

#Cmdiine