When you compile a unit or program that needs other units, the compiler will look for compiled versions of these units in the following way:
You can add a directory to the unit search path with the (-Fu (see page 5.1.3)) option. Every occurrence of one of this options will insert a directory to the unit search path. i.e. the last path on the command line will be searched first.
The compiler adds several paths to the unit search path:
/usr/local/lib/fpc/FPCVERSION
or /usr/lib/fpc/FPCVERSION |
whichever is found first.
C:\FPC\1.9.6\units\i386-win32
|
This is assuming the compiler was installed in the directory
C:\FPC\1.9.6
|
After this directory is determined , the following paths are added to the search path:
Here target must be replaced by the name of the target you are compiling for: this is a combination of CPU and OS, so for instance
/usr/local/lib/fpc/1.9.6/units/i386-linux/
|
or, when cross-compiling
/usr/local/lib/fpc/1.9.6/units/i386-win32/
|
The -Fu option accepts a single * wildcard, which will be replaced by all directories found on that location. For example, given the directories
rtl/units/i386-linux
fcl/units/i386-linux packages/base packages/extra |
fpc -Fu"*/units/i386-linux"
|
will have the same effect as
fpc -Furtl/units/i386-linux -Fufcl/units/i386-linux
|
since both the rtl and fcl directories contain further units/i386-linux subdirectories. The packages directory will not be added, since it doesn’t contain a units/i386-linux subdirectory.
Note that (for optimization) the compiler will drop any non-existing paths from the search path, i.e. the existence of the path (after wildcard and environment variable expansion) will be tested.
You can see what paths the compiler will search by giving the compiler the -vu option.
On systems where filenames are case sensitive (such as unix and linux), the compiler will :
This is necessary, since Pascal is case-independent, and the statements Uses Unit1; or uses unit1; should have the same effect.
It will do this first with the extension .pp and then with the extension .pas.
For instance, suppose that the file foo.pp needs the unit bar. Then the command
fpc -Fu.. -Fuunits foo.pp
|
will tell the compiler to look for the unit bar in the following places:
Also, unit names that are longer than 8 characters will first be looked for with their full length. If the unit is not found with this name, the name will be truncated to 8 characters, and the compiler will look again in the same directories, but with the truncated name.
If the compiler finds the unit it needs, it will look for the source file of this unit in the same directory where it found the unit. If it finds the source of the unit, then it will compare the file times. If the source file was modified more recent than the unit file, the compiler will attempt to recompile the unit with this source file.
If the compiler doesn’t find a compiled version of the unit, or when the -B option is specified, then the compiler will look in the same manner for the unit source file, and attempt to recompile it.
It is recommended to set the unit search path in the configuration file fpc.cfg. If you do this, you don’t need to specify the unit search path on the command-line every time you want to compile something.