Go to the previous, next section.

Glue Code Generator

This chapter describes a utility program which is useful in generating glue code for the Foreign Language Interface when building Runtime Systems and statically linked Development Systems (see section Foreign Language Interface with Static Linking).

The flinkage package, which may be loaded by the query

| ?- use_module(library(flinkage)).

is used to generate an `flinkage.c' file out of the foreign functions declarations in a set of Prolog files.

@
Files are opened and scanned. All definitions of the predicates foreign/(2-3) or foreign_file/2 found are asserted (into the flinkage module). The built-in predicate prepare_foreign_files/1 is then called. As argument is given the list of all files appearing as first arguments of the foreign_file/2 definitions in Files. Afterwards all asserted definitions are retracted.

Load directives encountered in the scanned files causes the files referenced in the directive to be scanned as well.

generate_flinkage/1 handles ql-files, as well as pl-files, with the constraint that all foreign/(2-3) and foreign_file/2 must be unit clauses and declared dynamic.

While scanning, any terms causing syntax error while reading are simply skipped over.

An example: Suppose you want to use both library(db) and library(random) in a runtime system. To generate the necessary `flinkage.c' file, do:

| ?- generate_flinkage([library(db),library(random)]).

Go to the previous, next section.