9.2.8 Creating the Linked Foreign Resource

Suppose we have a Prolog source file ex.pl containing:

% ex.pl
foreign(f1, p1(+integer,[-integer])). foreign(f2, p2(+integer,[-integer])). foreign_resource(ex, [f1,f2]). :- load_foreign_resource(ex).

and a C source file ex.c with definitions of the functions f1 and f2, both returning long and having a long as only parameter. The conversion declarations in ex.pl state that these functions form the foreign resource ex.

To create the linked foreign resource, simply type (to the Shell):

     % splfr ex.pl ex.c

The linked foreign resource ex.so (file suffix .so is system dependent) has been created. It will be dynamically linked by the directive :- load_foreign_resource(ex). when the file ex.pl is loaded. Linked foreign resources can also be created manually (see Runtime Utilities).

Dynamic linking of foreign resources can also be used by runtime systems. On some platforms, however, the executable must not be stripped for dynamic linking to work, i.e. its symbol table must remain.