Foreign modules may be linked to Prolog in three ways. Using
static linking, the extensions, a small description file and
the basic SWI-Prolog object file are linked together to form a new
executable. Using dynamic linking, the extensions are linked to
a shared library (.so
file on most Unix systems) or
dynamic-link library (.DLL
file on Microsoft platforms) and
loaded into the the running Prolog process. (24).
The static linking schema can be used on all versions of SWI-Prolog. The feature/2 predicate may be used to find out what other linking methods are provided for this version.
.DLL
files by means of open_dll/2 and
friends. See section 5.4.
If either the feature open_shared_object
or dll
is true, the library library(shlib)
provides a common
interface for loading foreign files from Prolog.
All described approaches have their advantages and disadvantages. Static linking is portable and allows for debugging on all platforms. It is relatively cumbersome and the libraries you need to pass to the linker may vary from system to system.
Loading shared objects or DLL files provides sharing and protection and is generally the best choice. If a saved-state is created using qsave_program/[1,2], an initialization/1 directive may be used to load the appropriate library at startup.
Note that the definition of the foreign predicates is the same, regardless of the linking type used.