2

I wasted a whole day on this and can't find a solution. As Google doesn't supply any other questions like this, I'm sure that I must be doing something wrong.

I have a fresh full install of swi-prolog 8.2.3.1 on windows 10. I made sure the graphic options where selected. There is an xpce folder in the main swipl folder. When I try to load the xpce lib into prolog I get the following error:

?- [library('pce')].
ERROR: source_sink `library(pce)' does not exist
ERROR: In:
ERROR:   [20] throw(error(existence_error(source_sink,...),_8462))
ERROR:   [16] '$resolve_source_path'(library(pce),_8494,[expand(true)]) at c:/program files/swipl/boot/init.pl:2315
ERROR:   [15] '$load_file'(library(pce),user,[expand(true)]) at c:/program files/swipl/boot/init.pl:2289
ERROR:    [9] <user>
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.

I tried to consult a file with :- use_module(library(pce)). in it and get the same error. I have no idea how to proceed. It works just fine with ubunutu on wsl on the same machine, but without any graphical interface, it does only help to make sure the commands are correct.

Further information on the outcome of @david-tonhofer's solution:

I have this file in "C:\Program Files\swipl\xpce\prolog\lib". So I tried the folliwing:

?- file_search_path(library,X).
X = app_config(lib) ;
X = swi(library) ;
X = swi(library/clp) ;
false.

2 ?- assertz(file_search_path(library,pce('prolog/lib'))).           
true.

3 ?- file_search_path(library,X).
X = app_config(lib) ;
X = swi(library) ;
X = swi(library/clp) ;
X = pce('prolog/lib').

4 ?- file_search_path(library,pce('prolog/lib')).
true.

5 ?- file_search_path(pce,X).
false.

6 ?- assertz(file_search_path(pce,'C:/Program Files/swipl/xpce/')).           
true.

7 ?- file_search_path(pce,X).
X = 'C:/Program Files/swipl/xpce/'.

8 ?- use_module(library(pce)).
true.
vaeng
  • 90
  • 15

2 Answers2

2

There should be a file

./swiplexe_8.3.14/lib/swipl/xpce/prolog/lib/pce.pl

in your installation directory.

Calling

?- use_module(library(pce)).

on the toplevel of Prolog or

:- use_module(library(pce)).

instructs it to load pce.pl found in the library path.

It could be your library path is incomplete....

Consult your search path by issuing

?- file_search_path(library,X).

X = app_config(lib) ;
X = swi(library) ;
X = swi(library/clp) ;
X = pce('prolog/lib').   <--- should be there

Extend your search path by issuing

?- assertz(file_search_path(library,SOME_PATH_AS_STRING_OR_ATOM)).

However, the fact

file_search_path(library,pce('prolog/lib')).

indicates a two-level lookup.

We also need to ascertain that pce is set:

I have this:

?- file_search_path(pce,X).
X = '/usr/local/logic/swiplexe_8.3.14/lib/swipl/xpce'.

So it may be necessary to issue

?- assertz(file_search_path(pce,DIR_OF_XPCE_AS_STRING_OR_ATOM)).
David Tonhofer
  • 14,559
  • 5
  • 55
  • 51
  • 1
    @vaeng Please try setting the fact `file_search_path(pce,DIR_OF_XPCE_AS_STRING_OR_ATOM)`; it might be the solution – David Tonhofer Dec 20 '20 at 17:51
  • @vaeng Make sure you have `pce('prolog/lib').`, not `pce('xpce/prolog/lib').` in the `file_search_path/1`. – David Tonhofer Dec 20 '20 at 18:00
  • 1
    And the entry fpor `pce` has to stop at `C:/Program Files/swipl/xpce/` – David Tonhofer Dec 20 '20 at 18:01
  • Thank you. That worked. When I start another session of swipl, all this is gone. Is there a way to safe it permanently? – vaeng Dec 20 '20 at 18:12
  • 1
    @vaeng Yes, there is init.pl, which is read when you start a session: See [user initialization file](https://eu.swi-prolog.org/pldoc/man?section=initfile). Add `:- ..` directives into there. I don't currently have anything in that file, so I don't know why it works out of the box for me. – David Tonhofer Dec 20 '20 at 18:19
  • Yes, that worked. Thanks a lot. It was a real big headache to solve. I hope this can help others you have a similar issue. – vaeng Dec 20 '20 at 18:29
0

Running the following two lines will work:

assertz(file_search_path(library,pce('prolog/lib'))).
assertz(file_search_path(pce,swi(xpce))).

In the second line, 'swi' is referring to the root folder of swipl. If you want to verify all the paths, here's an example:

?- file_search_path(X,Y).
X = swi,
Y = 'c:/program files/swipl' ;
X = library,
Y = app_config(lib) ;
X = library,
Y = swi(library) ;
X = library,
Y = swi(library/clp) .