6.7.3.3 Examples
  1. The character-based SICStus development system executable (sicstus) can be created using
              % spld --main=prolog -o sicstus
         

    This will create a development system that is dynamically linked and has no pre-linked foreign resources.

  2.           % spld --static -D --resources=random -o main -ltk8.0 -ltcl8.0
         

    This will create a statically linked executable called main that has the resource random pre-linked (statically). The linker will receive -ltk8.0 -ltcl8.0, which will work under UNIX (if Tcl/Tk is installed correctly) but will probably fail under Windows.

  3. An all-in-one executable with a home-built foreign resource.

    This example is similar to the example in All-in-one Executables, with the addition of a foreign resource of our own.

                                       
    % foo.pl
    :- use_module(library(system)). :- use_module(library(clpfd)). :- load_foreign_resource(bar). % This will be called when the application starts: user:runtime_entry(start) :- %% You may consider putting some other code here... write('hello world'),nl, write('Getting date:'),nl, datime(Date), % from system write(Date),nl, ( all_different([3,9]) -> % from clpfd write('3 != 9'),nl ; otherwise -> write('3 = 9!?'),nl ), '$pint'(4711). % from our own foreign resource 'bar'
                                       
    % bar.pl
    foreign(print_int, '$pint'(+integer)). foreign_resource(bar, [print_int]).
                                    
    /* bar.c */
    #include <sicstus/sicstus.h> #include <stdio.h> #include "bar_glue.h" extern void print_int(long a); void print_int(long a) { printf("a=%lu\n", a); }

    To create the saved-state foo.sav we will compile the file foo.pl and save it with save_program('foo.sav'). When compiling the file the directive :- load_foreign_resource(bar). is called so a dynamic foreign resource must be present.

    Thus, first we build a dynamic foreign resource.

              % splfr bar.c bar.pl
         

    Then we create the saved-state.

              % sicstus --goal "compile(foo), save_program('foo.sav'), halt."
         

    We also need a static foreign resource to embed in our all-in-one executable.

              % splfr --static bar.c bar.pl
         

    Lastly we build the all-in-one executable with spld. We do not need to list the foreign resources needed. spld will extract their names from the .sav file. Adding the --verbose option will make spld output lots of progress information, among which are the names of the foreign resources that are needed. Look for “Found resource name” in the output.

              % spld --verbose --static --main=restore --respath=. --resources=foo.sav=/mystuff/foo.sav --output=foo
         

    In this case four foreign resource names are extracted from the .sav file: bar, clpfd, random and system. The source file foo.pl loads the foreign resource named bar. It also uses library(system) module, which loads the foreign resource named system, and library(clpfd) module, which loads the foreign resources named clpfd and random.

    By not listing foreign resources when running spld, we avoid the risk of omitting a required resource.


Send feedback on this subject.