6.8.2 Building for a Target Machine

The following example shows how to build an application with a
dynamically loaded foreign resource in such a way that it can be
deployed into an arbitrary folder on a target system that does not have
SICStus installed. The example is run on Linux but it would be very
similar on other platforms.

The example consists of three source files, one toplevel file
(main.pl) which in turn loads a module-file (b.pl). The
latter also loads a foreign resource (b.c).

The initial directory structure, and the contents of the source files
can be seen from the following transcript:

(instead of creating main.exe you could use the generic runtime system
sprt.exe provided as part of the installation (see Generic Runtime Systems)).

Please note: it is important that main.sav be saved to a
folder that is the “root” of the folder tree. The folder in which the
saved-state is created (.../build/ above) is treated
specially by save_program/[1,2] and by restore/1. This
special handling ensures that myfiles/b.so will be found relative
to the location of main.sav when main.sav is restored on
the target system. See Saving for details.

Next, the necessary runtime files must be copied from the SICStus
installation:

The folder build/myfiles/ contains some files that don't need to
be present on the target machine, i.e. the source files. The following
transcript shows how a new folder, target/, is created that
contains only the files that need to be present on the target system.

Note that target/myfiles/b.so was found since its location
relative the directory containing the saved-state (main.sav) is
the same on the target system as on the build system.

The folder target/ can now be moved to some other system and
target/main.exe will not depend on any files of the build
machine.

As a final example, the following transcripts show how the runtime
system can be debugged on the build machine. It is possible to do this
on the target system as well, if the necessary files are
made available. See Debugging Runtime Systems for more information.

First, the development system files and the license file must be made
available:

To tell the runtime system to start a development system. you can set the
SP_USE_DEVSYS environment variable as shown below. You could also
set SP_ATTACH_SPIDER and debug in the SICStus IDE
(see Debugging Runtime Systems).