As I don’t have the time to write up an entire Wiki article on this, a few things you should consider.
- What is the present working directory. Use the predicate pwd/0, e.g.
?- pwd.
% c:/users/groot/documents/prolog/
true.
-
Ensure that the code in modules such as
use_module(utilities).
has a file namedutilities.pl
in the present working directory. -
You can change the working directory in code using working_directory/2 with a directive, e.g.
:- working_directory(_,'C:/Users/Groot/Documents/Projects/SWI-Prolog/my_code').
- If you are like me and switch between different operating systems then consider
:- if(current_prolog_flag(windows,true)).
:- working_directory(_,'C:/Users/Groot/Documents/Projects/SWI-Prolog/my_code').
:- elif(current_prolog_flag(unix,true)).
:- working_directory(_,'/mnt/c/Users/Groot/Documents/Projects/SWI-Prolog/my_code').
:- endif.
- A quick way to check if a file can be loaded is to try to load it manually using consult/1 or with the preferred syntactic sugar of
[<file name>]
, e.g.
?- [my_code].
- For more advanced use cases use file_search_path/2. This is used often in the SWI-Prolog source code. (search)
HTH
Also see:
Properties of modules and predicates
SWI-Prolog has check_installation/0
Using SWI-Prolog’s modules
Modules in SWI Prolog
Dwim and other errors, with very simple facts