Move swipl binary to a different folder

I’m using: SWI-Prolog version (current swipl-devel, linux)

I want the code to: compile and run in a different folder than CMAKE_INSTALL_PREFIX

But what I’m getting is: ERROR: autoload loop

My code looks like this:

cd swipl-devel
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=~/swipl ..
make install
cd ~/swipl/bin
[works fine]
cd ~
mkdir xx
mv swipl xx
cd xx/swipl/bin
[Error: autoload loop]
ls ../lib/swipl
[folder with boot.prc, among others]
./swipl --home=../lib/swipl
[Error: autoload loop]

The use case is an R package that embeds swipl. When I want to compile an R package, I do not yet know the destination folder.

Your help is much appreciated.

Best regards,


If you run one of these queries, you can see all the possibilities that are tried:

?- absolute_file_name(library(foo), Z, [solutions(all), access(none)]).


?- file_search_path(library, Z).

You may need to asserta/1 or assertz/1 some file_search_path/2 facts to get the effect you want.

Seems you are doing more. If I just move the tree I get

swipl: error while loading shared libraries: cannot open shared object file: No such file or directory

which is to be expected as swipl uses the RPATH that tells it where to find If I set LD_LIBRARY_PATH to fix that, the moved installation directory works just fine.

You’re right. Now it’s working. Maybe an old swipl installation was lying around elsewhere and caused some interference.

Thank you.

There’s something else: I attach it here, since it is only a question, and maybe too unimportant for a separate thread.

swipl --dump-runtime-variables returns a variable PLLIB (e.g., “-lswipl”), as well as PLLIBDIR, pointing to the directory where is found. I find this useful.

I want to build a pack with c/c++ code, the script provides a few variables, including, among others, SWILIB=’-lswipl’, but not SWILIBDIR. I am wondering if the latter can be added without harm?

I have now created a PR to add a variable SWILIBDIR to the build environment (basically copy-pasting the respective code from library/ Plus another PR in plweb-www to update the documentation.

What exactly do you want to link? Packs are normally there to create a shared object that can be loaded from SWI-Prolog. The shared object should be linked using swipl-ld or, when using the linker directly, use $LDSOFLAGS and $SWISOLIB. Here, if there is no need to link to because the symbols are already available (ELF systems such as Linux) this provides no linking. That allows the shared object to be used with any compatible version of SWI-Prolog. If linking is required ((X)COFF executables), $LDSOFLAGS provides the required -L flag and possible additional link flags and $SWISOLIB is -lswipl.

You’re right. The -lswipl isn’t needed under linux, and so -L… isn’t either. Ok, learned something new again.

Sorry for bothering you with this.