How to create a standalone from a SICStus prolog file

After having searched the internet, I e-mailed SICS and got two methods to create a standalone. I was using:

To create a standalone .exe file you need a C-compiler that matches your installation of SICStus. These C-compilers are included in the following versions of Visual C++.

Although there seems to be some backwards compability since I'm using SICStus VC9 and Visual Studio 2010.

To run the .exe file on another computer that computer will need the corresponding C-library(which is called Redistributable Packages by Microsoft). They can be downloaded here:

This is the example pl file we will be compiling. It's using one of SICStus built-in libraries namely library(sets). Lets call it test.pl

:- module(test, []).
:- use_module(library(sets), [intersection/3]).

main :-

%% argv is the commands passed on the command line (or after the
%% option '--' if run in a development system).
current_prolog_flag(argv, Argv),
sort(Argv, Set1),
Set2 = [a, c, g],
intersection(Set1, Set2, Intersection),
format('The intersection of ~w and ~w is ~w~n', [Set1, Set2, Intersection]).


% .sav-file entry point
user:runtime_entry(start) :-
main.
%% test.pl

Method 1:

Create the .sav-file by compiling from the SICStus top level. This can be done using the SICStus interpreter,emacs, SPIDER or from the command line by navigating to the SICStus binary folder "C:\Program Files (x86)\SICStus Prolog VC10 4.2.1\bin" and typing:

sicstus.exe -i

From the sicstus top level, type the following:

|?- compile('C:\filepath...\test'), save_program('C:\filepath...\test.sav').

Then end your session using

|?- halt.

Now you need to load some settings to make your C-compiler available. Do this by navigating to (might be slightly different depending on your version of visual studio) C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ run the vcvarsall file.

vcvarsall.bat x86

Remember the x86.

Then navigate to the SICStus binary folder and build your exe file using spld.exe. The flag --static makes sure that all you'll need will be in the .exe file though the target machine must have the correct C-library installed.

C:\Program Files (x86)\SICStus Prolog VC10 4.2.1\bin>spld.exe --static c:\long filepath...\test.sav -o c:\long filepath...\test1.exe

This should create an .exe file that will run on any computer with the right C library.

METHOD 2

Create the save file again. It's important that you name it main.sav.

|?- compile('C:\filepath...\test'), save_program('C:\filepath...\main.sav').

Create a new folder for this example. Copy your main.sav file to the folder. Copy sprt.exe, sprt4-2-x.dll and sprt.sav from the SICStus installation's bin folder into your new folder.

To run your program, run sprt.exe. Now your folder contains everything you need to run your .exe on another computer(except for the C library).

I hope this will help someone stuck in the same situation as I was.

This is a translation of a mail conversation with Per Mildner at SICS. The entire conversation (IN SWEDISH) can be found here