Subject: Re: foreign code chicken/egg scenario

From: Jan Wielemaker <[email-masked]>
Date: Wed, 8 Nov 2000 17:21:48 +0100

On Wed, 08 Nov 2000, Paul Singleton wrote:
>Jan Wielemaker wrote:
>
>> Sounds like dangerous practice.
>
>Is load_foreign_library('MYLIB.DLL') unsafe where the DLL is (unknown
>to Prolog) already linked?  If so, is there a workaround?
>
>> If your dll embeds Prolog simply call
>> the install() function after PL_initialise().
>
>OK, but sometimes my DLL will be dynamically loaded by Prolog (e.g.
>upon autoloading a native library which refers to it).
>
>I'm trying to deploy MYLIB and LIBPL as "components", which work
>together regardless of which is the chicken and which is the egg :-)

This gets into nitty-gritty aspects of dynamic loading, differing
from system to system.  I'm not an expert in these matters.  The most
portable is probably to use a check-before-loading approach.  This
is what I generally do it I don't know whether a foreign module is
linked statically or should be linked on-the-fly.  So you get:

load_lib_xxx :-
	current_predicate(_, yyy(_)), !.
load_lib_xxx :-
	load_foreign_library(foreign(xxx)).

:- initialization
	load_lib_xxx.

	Regards --- Jan