Go to the first, previous, next, last section, table of contents.


Glue Code Generator

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 shared object files or DLLs:

runtime kernel
The SICStus runtime kernel, usually `$SP_PATH/../libsprt37.so' under UNIX, or `%SP_PATH%\..\sprt37.dll' under Windows, and
development kernel
The SICStus development kernel, usually `$SP_PATH/../libspds37.so' under UNIX, or `%SP_PATH%\..\spds37.dll' under Windows.

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)
Files are loaded as by 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 and optionally the development kernel.

The following predicates, available in Development Systems only, 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)
where +ResourceNames is a list of the resource names and +CFile is the file where to write the generated code.

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)
where ResourceName is the name of the resource, SourceFile is the Prolog source file containing the resource conversion declarations and CFile is the file where to write the generated code.

Finally, compile and link the glue code files with the user code, libraries and the runtime and optionally the 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.


Go to the first, previous, next, last section, table of contents.