Node:Creating the Linked Foreign Resource, Next:, Previous:Init and Deinit Functions, Up:Calling C from Prolog

Creating the Linked Foreign Resource

Suppose we have a Prolog source file containing:

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 state that these functions form the foreign resource ex.

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

% splfr ex.c

The linked foreign resource (file suffix .so is system dependent) has been created. It will be dynamically linked by the directive :- load_foreign_resource(ex). when the file 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.