Many applications use packages that include foreign language
components compiled to shared objects or DLLs. This code is normally
loaded using
use_foreign_library/1
and the foreign
file search path. Below is an example from
the socket
library.
:- use_foreign_library(foreign(socket)).
There are two options to handle shared objects in runtime
applications. The first is to use the foreign(save)
option
of qsave_program/2
or the --foreign=save commandline option. This causes
the dependent shared objects to be included into the resource archive.
The use_foreign_library/1
directive first attempts to find the foreign file in the resource
archive. Alternatively, the shared objects may be placed in a directory
that is distributed with the application. In this cases the file search
path foreign
must be setup to point at this directory. For
example, we can place the shared objects in the same directory as the
executable using the definition below. This may be refined further by
adding subdirectories depending on the architecture as available from
the Prolog flag arch.
:- multifile user:file_search_path/2. user:file_search_path(foreign, Dir) :- current_prolog_flag(executable, Exe), file_directory_name(Exe, Dir).