From jan@swi.psy.uva.nl  Wed Nov  8 17:27:57 2000
Received: from gollem.swi.psy.uva.nl (gollem [145.18.152.30])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id RAA26189;
	Wed, 8 Nov 2000 17:27:57 +0100 (MET)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id RAA32652;
	Wed, 8 Nov 2000 17:26:56 +0100
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: Paul Singleton <p.singleton@keele.ac.uk>,
        SWI Prolog <prolog@swi.psy.uva.nl>
Subject: Re: foreign code chicken/egg scenario
Date: Wed, 8 Nov 2000 17:21:48 +0100
X-Mailer: KMail [version 1.0.28]
Content-Type: text/plain
References: <3A094EE8.C7581051@keele.ac.uk> <00110815182601.30820@gollem> <3A097863.2FBBF5D0@keele.ac.uk>
In-Reply-To: <3A097863.2FBBF5D0@keele.ac.uk>
MIME-Version: 1.0
Message-Id: <00110817265503.30820@gollem>
Content-Transfer-Encoding: 8bit

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

