6.2.4 Interface Predicates


Unless a foreign resource with the same name as Resource has been statically linked, the linked foreign resource specified by Resource is linked into the Prolog load image. In both cases, the predicates defined by Resource are installed, and any init function is called. Dynamic linking is not possible if the foreign resource was linked using the --static option.

If a resource with the same name has been previously loaded, then it will be unloaded, as if unload_foreign_resource(Resource) were called, before Resource is loaded.

An example of usage of load_foreign_resource/1 can be found in its reference page, mpg-ref-load_foreign_resource.


Any deinit function associated with ResourceName, a resource name, is called, and the predicates defined by ResourceName are uninstalled. If ResourceName has been dynamically linked, then it is unlinked from the Prolog load image.

If no resource named ResourceName is currently loaded, then an existence error is raised.

For backward compatibility, ResourceName can also be of the same type as the argument to load_foreign_resource/1. In that case the resource name will be derived from the absolute file name in the same manner as for load_foreign_resource/1. Also for backward compatibility, unload_foreign_resource/1 is a meta-predicate, but the module is ignored. See mpg-ref-unload_foreign_resource.

Please note: all foreign resources are unloaded before Prolog exits. This implies that the C library function atexit(func) cannot be used if func is defined in a dynamically linked foreign resource.

Send feedback on this subject.