[fpc-devel] Uses clause with in patrh
Adriaan van Os
adriaan at adriaan.biz
Wed Feb 4 14:54:58 CET 2026
Section 16.1 Programs of the FreePascal Language Reference Guide describes the uses clause and also
discusses the optional in keyword with a path string literal. It says
program programb;
uses unita in ’..\unita.pp’;
unita is searched in the parent directory of the programb source file.
However, the actual behaviour of the [331 macOS] compiler seems to be, not to take a relative path
from the main program (or library) file, but from the OS process current path !! I would rather
prefer the documented behaviour, as relying on the current path is risky and ambiguous and it could
lead to very nasty bugs.
Regards,
Adriaan van Os
[Mac-mini:~/fpc-test/usespath] administrator% ls -l -R
total 0
drwxr-xr-x 4 administrator staff 128 Feb 4 14:46 prog
drwxr-xr-x 3 administrator staff 96 Feb 4 14:46 unit
./prog:
total 8
-rw-r--r--@ 1 administrator staff 78 Feb 4 14:32 testusespath.pas
./unit:
total 8
-rw-r--r--@ 1 administrator staff 105 Feb 4 14:31 useme.pas
[Mac-mini:~/fpc-test/usespath] administrator% cat prog/testusespath.pas
program testusespath;
uses
useme in '../unit/useme.pas';
begin
A
end.
[Mac-mini:~/fpc-test/usespath] administrator% cat unit/useme.pas
unit useme;
interface
procedure A;
implementation
procedure A;
begin
writeln( 'use me')
end;
end.
Mac-mini:~/fpc-test/usespath/prog] administrator% fpc testusespath.pas
Free Pascal Compiler version 3.2.4-rc1 [2025/10/15] for x86_64
Copyright (c) 1993-2024 by Florian Klaempfl and others
Target OS: Darwin for x86_64
Compiling testusespath.pas
Compiling ../unit/useme.pas
Assembling useme
Assembling testusespath
Linking testusespath
ld: warning: -multiply_defined is obsolete
-macosx_version_min has been renamed to -macos_version_min
23 lines compiled, 11.2 sec
[Mac-mini:~/fpc-test/usespath/prog] administrator% cd ..
[Mac-mini:~/fpc-test/usespath] administrator% fpc prog/testusespath.pas
Free Pascal Compiler version 3.2.4-rc1 [2025/10/15] for x86_64
Copyright (c) 1993-2024 by Florian Klaempfl and others
Target OS: Darwin for x86_64
Compiling prog/testusespath.pas
testusespath.pas(5,3) Fatal: Can't find unit useme used by testusespath
Fatal: Compilation aborted
Error: /usr/local/bin/ppcx64 returned an error exitcode
More information about the fpc-devel
mailing list