[fpc-devel] Include file search order - clarifications

Martin Frb lazarus at mfriebe.de
Fri Jan 23 16:52:35 CET 2026


Maybe I missed some docs... But I found:

https://www.freepascal.org/docs-html/prog/progsu40.html#x47-460001.2.40
>
>  1. It will look in the path specified in the include file name.
>  2. It will look in the directory where the current source file is.
>  3. it will look in all directories specified in the include file
>     search path.
>

That leaves some questions though...

   {$I C:\test.inc}
- The path in the include file (point 1) is C:\ and that will be searched.
- 2 and 3 will NOT be searched (according to tests)

   {$I foo\test.inc}
   {$I .\foo\test.inc}
   {$I ..\foo\test.inc}
- the path in the include file itself is incomplete, and can't be 
searched as such
- 2 and 3 seem to be searched, OR RATHER it will search relative to them.

I am not sure, if I had a hidden setting, but it seems to me, there is 
ONE MORE path that is searched.
- The path in which compilation started (that is the "current dir" / NOT 
the dir of the main unit/program)

Having

a/tmp/project.pp
     uses unit1 in 'a/tmp/foo/unit1.pas'

a/tmp/foo/unit1.pas
     {$I ./bar.inc}

a/bar.inc


and running
   cd a
   fpc tmp/project.pp

will find "bar.inc" in
- directory "a"  => current dir
- a/tmp/foo  => the dir of the unit (point 2)

I don't know the search order though.

I haven't done tests with extra include path...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20260123/1a82887f/attachment.htm>


More information about the fpc-devel mailing list