If your application uses files that are not part of the saved program
such as database files, configuration files, etc., the runtime version
has to be able to locate these files. The file_search_path/2
mechanism in combination with the -palias command line
argument is the preferred way to locate runtime files. The first step is
to define an alias for the top-level directory of your application. We
will call this directory
gnatdir in our examples.
A good place for storing data associated with SWI-Prolog runtime
systems is below the emulator's home directory.
swi is a
predefined alias for this directory. The following is a useful default
definition for the search path.
The application should locate all files using absolute_file_name.
gnatdir contains a file config.pl to
define the local configuration. Then use the code below to load this
configure_gnat :- ( absolute_file_name(gnatdir('config.pl'), ConfigFile) -> consult(ConfigFile) ; format(user_error, 'gnat: Cannot locate config.pl~n'), halt(1) ).
Suppose the system administrator has installed the SWI-Prolog runtime
/usr/local/lib/rt-pl-3.2.0. A user wants to
gnat will look for its
/usr/local/lib/rt-pl-3.2.0/gnat where the user cannot
The user decides to install the
gnat runtime files in
/users/bob/lib/gnat. For one-time usage, the user may
decide to start
gnat using the command:
% gnat -p gnatdir=/users/bob/lib/gnat