Finding the Prolog resources (boot.prc
startup file and (foreign) libraries) has always been problematic. SWI-Prolog supports quite a few ways to arrange the installed system. By default this is a self-contained directory that is, as far as the dynamic linking of the system supports, relocatable. Alternatively, it supports various alternatives that are commonly used in Unix derived systems, where binaries, libraries, documentation and other resources all have their own place. Finally, the user may create executables, that also have to find their resources. This was all pretty muddy, notably when SWI-Prolog is embedded in e.g., Python, Java, C++, … The algorithm was (and is),
- Check
--home=DIR
option. - Check the environment variables
SWI_HOME_DIR
orSWIPL
(compatibility). - Locate the reference file. This is either the running executable or the
libswipl.dll
(Windows). On success,- Find a file
swipl.home
in the directory above this file - Read its content and use this as a relative path to the home directory. This is the typical way for the relocatable bundle to find the location of the bundle.
- Find a file
- When configured, find the home as a relative location to the directory in which the above reference file resides. This is used on e.g. MSYS and Conda.
- Use some compiled in location.
On failure it printed the famous message
“Could not find system resources”
While the basic algorithm is still the same, some fine tuning has been done
- Install a file
ABI
in the home that provides the SWI-Prolog ABI version (seeswipl --abi-version
). That allows us to discover whether or not the found home is compatible and print a message if not, rather than simply crashing. - Only accept
--home=DIR
as one and only place to look. If the specified location is not a valid home, give up with an error. - Otherwise, try all above alternatives, validating the ABI.
- If no home is found, but a saved state is attached to one of the reference files or specified as
-x state
, continue without a home. This assumes all resources required are in the state. - Otherwise we used to get the above fatal error. This is still a fatal error, but before dying it does the same search again while printing why it tried which location and why the result was rejected.
That should lead to less issues when embedding Prolog while there are multiple Prolog installations on your system. If things still fail the diagnosis should be easier.