This chapter describes utilities useful for generating glue code for the Foreign Language Interface when building statically linked Runtime Systems or Development Systems (see section Interface Predicates).
This library module can be loaded by the query
| ?- use_module(library(flinkage)).
and refers to the following object files:
The following predicate can be used to generate a glue code file
`flinkage.c' file out of any old-style foreign_file/2
and
foreign/2-3
declarations found in a set of Prolog files for use
in a statically linked executable.
Note: this is provided for backwards compatibility only. We
recommend using foreign resources instead, which can be dynamically
linked:
generate_flinkage(+Files)
use_module/1
. Calls to
load_foreign_files/2
are intercepted by means of the goal
expansion mechanism. The file `flinkage.c' is generated out of the
declarations found.
Finally, compile and link the `flinkage.c' file with the user code,
libraries and the runtime or development kernel.
The following predicates provide alternative methods to building executables or linked foreign resources compared to the methods described in section Creating the Executable, section Development Systems and section Creating the Linked Foreign Resource. If the default method doesn't work as expected for some reason or you wish to use an Integrated Development Environment etc., the following outlines the necessary steps. To build an executable:
First, decide which foreign resources are to be statically linked and create a resource table file as follows:
prepare_resource_table(+ResourceNames,+CFile)
The next step is to create linked foreign resources from the foreign resources which are to be statically linked. Produce, for each foreign resource, a glue code file using:
prepare_foreign_resource(+ResourceName,+SourceFile,+CFile)
Finally, compile and link the glue code files with the user code, libraries and the runtime or development kernel. Further information (platform specific) is provided with the distribution.
To build a dynamic linked foreign resource:
Produce a glue code file using prepare_foreign_resource/3
. Check
the provided platform specific notes for compiler options needed and
compile the glue code file and the user code files. Likewise check the
notes on how a dynamic linked foreign resource is implemented on this
platform and link the object files to an appropriate object.