I want to run swi-prolog program on the machine (actually a server) where there is no prolog installed.
The prolog code swipl_test.pl
:
main :- write('Hello, world\n').
On the local machine 4.4.0-64-generic #85~14.04.1-Ubuntu SMP Mon Feb 20 12:10:54 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
making the binary hello
with SWI-Prolog version 7.2.3 for amd64
:
swipl --goal=main --toplevel=halt --stand_alone=true --foreign=save -o hello1 -c swipl_test.pl
Moving hello
on the remote machine 2.6.32-5-amd64 #1 SMP Wed Jun 17 16:09:06 UTC 2015 x86_64 GNU/Linux
gives the following error:
error while loading shared libraries: libswipl.so.7.2: cannot open shared object file: No such file or directory
How I can prepare a self-contained binary from a prolog code? I do not have sudo rights on the remote machine.
By default, SWI-Prolog is installed as‘swipl'. The command line arguments of SWI-Prolog itself and its utility programs are documented using standard Unix man pages. SWI-Prolog is normally operated as an interactive application simply by starting the program:
After SWI-Prolog has been installed on a Windows system, the following important new things are available to the user: A folder (called directory in the remainder of this document) called swipl containing the executables, libraries, etc., of the system.
SWI-Prolog depends on zlib. To compile it to WebAssembly: This will download and build zlib into the zlib-1.2.11 subdirectory in your home directory. Do you want me to run git submodule update --init?
After starting Prolog, one normally loads a program into it using consult/1, which may be abbreviated by putting the name of the program file between square brackets. The following goal loads the file likes.pl containing clauses for the predicates likes/2 :
I had the same problem and i could solve it looking for the shared libraries necessary for the execution of my program. You can find these libraries by executing the ldd
command. Once you have them, you can distribute them in the same directory as your executable and set the LD_LIBRARY_PATH
variable so that the executable can find them.
This happens because, as clarified in the documentation, when using the option --stand_alone = true
the executable becomes a copy of swipl with the saved state and, if SWI-Prolog is statically linked (by default in Linux/386) and the state does not use external packages, there will be no problems to run the program on another machine. Otherwise (our case) the shared objects must be made available so that the executable can find them. In Linux, these shared objects are found using ldd
(in your case, the library libswipl.so.7.2
). Therefore, you should look for this library (by default in /usr/lib) and copy it to the directory of your executable to distribute it with it. Then, in the machine where you are going to run the program, you must set the LD_LIBRARY_PATH
variable so that the executable knows where to find those libraries that it needs to run, that is, the same directory where it is, or use chrpath(1)
to change the address where the executable will search.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With