FreeBASIC

From Gentoo Wiki
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it - how to get started.

FreeBASIC is a modern, self-hosting, object oriented, BASIC compiler with a QuickBASIC compatibility mode. FreeBASIC is an evolution of the BASIC programming language released under the GPL.

While operating in native "fb" mode, FreeBASIC provides for namespaces, object oriented programming, function overloading, inline assembly, and a C-style preprocessor.

In "qb" mode FreeBASIC is highly compatible with Microsoft QuickBASIC, allowing many legacy BASIC programs targeting the QuickBASIC interpreter to compile and run unaltered. Additionally, there is a hybrid "fblite" mode that keeps some measure of QuickBASIC compatibility while enabling a subset of modern features from "fb" mode. This permits the gradual modernization of an existing BASIC codebase.

FreeBASIC runs on multiple platforms including Linux and Microsoft Windows; even the DOS port is still maintained.

Installation

FreeBASIC is in the Gentoo Project:GURU repository, not the main Gentoo ebuild repository.

USE flags

  • gpm
  • libffi
  • opengl
  • X

Emerge

root #emerge --ask dev-lang/fbc

Invocation

user $fbc --help
usage: fbc [options] <input files>
input files:
  *.a = static library, *.o = object file, *.bas = source
  *.rc = resource script, *.res = compiled resource (win32)
  *.xpm = icon resource (*nix/*bsd)
options:
  @<file>          Read more command line arguments from a file
  -a <file>        Treat file as .o/.a input file
  -arch <type>     Set target architecture (default: 486)
  -asm att|intel   Set asm format (-gen gcc|llvm, x86 or x86_64 only)
  -b <file>        Treat file as .bas input file
  -c               Compile only, do not link
  -C               Preserve temporary .o files
  -d <name>[=<val>]  Add a global #define
  -dll             Same as -dylib
  -dylib           Create a DLL (win32) or shared library (*nix/*BSD)
  -e               Enable runtime error checking
  -ex              -e plus RESUME support
  -exx             -ex plus array bounds/null-pointer checking
  -export          Export symbols for dynamic linkage
  -forcelang <name>  Override #lang statements in source code
  -fpmode fast|precise  Select floating-point math accuracy/speed
  -fpu x87|sse     Set target FPU
  -g               Add debug info, enable __FB_DEBUG__, and enable assert()
  -gen gas|gcc|llvm  Select code generation backend
  [-]-help         Show this help output
  -i <path>        Add an include file search path
  -include <file>  Pre-#include a file for each input .bas
  -l <name>        Link in a library
  -lang <name>     Select FB dialect: fb, deprecated, fblite, qb
  -lib             Create a static library
  -m <name>        Specify main module (default if not -c: first input .bas)
  -map <file>      Save linking map to file
  -maxerr <n>      Only show <n> errors
  -mt              Use thread-safe FB runtime
  -nodeflibs       Do not include the default libraries
  -noerrline       Do not show source context in error messages
  -noobjinfo       Do not read/write compile-time info from/to .o and .a files
  -nostrip         Do not strip symbol information from the output file
  -o <file>        Set .o (or -pp .bas) file name for prev/next input file
  -O <value>       Optimization level (default: 0)
  -p <path>        Add a library search path
  -pic             Generate position-independent code (non-x86 Unix shared libs)
  -pp              Write out preprocessed input file (.pp.bas) only
  -prefix <path>   Set the compiler prefix path
  -print host|target  Display host/target system name
  -print fblibdir  Display the compiler's lib/ path
  -print x         Display output binary/library file name (if known)
  -profile         Enable function profiling
  -r               Write out .asm/.c/.ll (-gen gas/gcc/llvm) only
  -rr              Write out the final .asm only
  -R               Preserve temporary .asm/.c/.ll/.def files
  -RR              Preserve the final .asm file
  -s console|gui   Select win32 subsystem
  -showincludes    Display a tree of file names of #included files
  -static          Prefer static libraries over dynamic ones when linking
  -strip           Omit all symbol information from the output file
  -t <value>       Set .exe stack size in kbytes, default: 1024 (win32/dos)
  -target <name>   Set cross-compilation target
  -title <name>    Set XBE display title (xbox)
  -v               Be verbose
  -vec <n>         Automatic vectorization level (default: 0)
  [-]-version      Show compiler version
  -w all|pedantic|<n>  Set min warning level: all, pedantic or a value
  -Wa <a,b,c>      Pass options to 'as'
  -Wc <a,b,c>      Pass options to 'gcc' (-gen gcc) or 'llc' (-gen llvm)
  -Wl <a,b,c>      Pass options to 'ld'
  -x <file>        Set output executable/library file name

Troubleshooting

FreeBASIC complains about circular dependencies at install time

FreeBASIC is a self-hosting compiler, this means that the FreeBASIC compiler is implemented in FreeBASIC itself. Therefore, in order to build FreeBASIC a relatively recent version of the FreeBASIC compiler must already exist on the system, thus the circular dependency.

In order to get around the circular dependency problem the creators of FreeBASIC created a minimal FreeBASIC compiler written in C called fbc-bootstrap. This implements just enough FreeBASIC to compile the compiler itself. As of this writing all versions of FreeBASIC are marked as unstable; as is the case with all packages in GURU. To resolve the circular dependency, ensure that /etc/portage/package.accept_keywords/ is configured to accept both dev-lang/fbc and dev-lang/fbc-bootstrap as unstable builds for your architecture. Thereafter portage should build both packages without issue.

Once FreeBASIC is installed the dev-lang/fbc-bootstrap package is no longer required as any recent version of FreeBASIC can be used to compile a more recent version.

Removal

Unmerge

root #emerge --ask --depclean --verbose dev-lang/fbc

See also

  • Bash — the default shell on Gentoo systems and a popular shell program found on many Linux systems.
  • Python — an extremely popular cross-platform object oriented programming language.

External Resources