[fpc-pascal] How to compile program from command line on Linux?

Guillermo Martínez Jiménez gmartinez at burdjia.com
Mon Dec 16 19:00:25 CET 2024


Use FPC from command line is easy if you're not using the LCL (the
Lazarus Component Library).

If you're using the LCL they explained in the other answers, but if you
just use the RTL then the easiest way is just calling FPC from the
same directory you have the sources:

~$ fpc theprogram

That will compile the program at "theprogram.pas" with default
configuration (the fpc.cfg file).

There are a lot of options you can see just with:

~$ fpc -h | more

In most cases I create directories "src/", "obj/" and "bin/" and then I
use a bash script like this:

#!/bin/sh
# Debug (GDB).
OPTIONS='-O1 -gw3 -gl -vwn -Ci -Cr -Ct -CR -Co -Sa -gh'
# Release.
# OPTIONS='-O3 -CX -XX -Xs -vw'
FLAGS="$OPTIONS -Sh -Si -l"
DIALECT='-MObjFPC'
UNITS='-Fusrc'
OUTPUT='-FUobj -FEbin'
FILE='src/programfile.pas'

FULL="$FLAGS $DIALECT $UNITS $OUTPUT $FILE"
fpc $FULL

I hope this helps.


More information about the fpc-pascal mailing list