Foreign modules may be linked to Prolog in two 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 into the running Prolog process.
Both approaches have their advantages and disadvantages. Static linking is portable and allows for symbolic debuggers to be used. It also ensures that the text of the extensions is part of the text-segment of the process, providing protection and sharing on operating systems that offer these features (Unix). Dynamic linking does not require rebuilding the entire Prolog system. C-code is loaded while Prolog is running. A new executable may be created using save_program/1. Unfortunately dynamic linking is non-portable and puts the incrementally loaded code in the data-segment of the process.
In general, we advice static loading for large extensions and dynamic loading when an application needs to load only a few C-defined predicates.