[PPL-devel] Re: [SWIPL] Problem with plld?

Jan Wielemaker wielemak at science.uva.nl
Sat Nov 5 10:22:19 CET 2005


On Friday 04 November 2005 22:10, Roberto Bagnara wrote:
> > P.s.	It may be wise to consider turning the ppl extension into a
> > 	library that is dynamically loaded in SWI-Prolog.  No more need
> > 	to recompile it for each new version of SWI-Prolog, easier to
> > 	combine with other packages.
>
> It sounds very interesting: how can we do that?

Not really knowing what ppl does (well, looked at the website for 5
minutes) and what role Prolog is playing in the picture, the general
idea of combining Prolog with some library is that the library
provides predicates for Prolog and possibly makes calls to Prolog. Then
there is a `main' program, that either has to be Prolog or the thing you
link to. The latter is an option if the external thing is by nature
interactive, but in general you want the interactive Prolog shell to be
the main routine. As XPCE shows, SWI-Prolog even allows access to the
interactive toplevel for X11 and Windows GUI applications, although this
complicates the issues a bit. Finally there is the issue of
initialisation.

Normally, try to compile the thing you want to add to Prolog into a
shared object/dll, for now named mylib.so. You create this using
"plld -shared mylib ..." Make sure this library exports a C-function
install_mylib() that calls whatever you need to do to register
predicates and initialise the library. Then write mylib.pl stating

:- module(mylib,
	  [ foo/1,
	    bar/2,
	    ...
	  ]).
:- initialization load_foreign_library(foreign(mylib)).

and make sure mylib.so is found on the search path foreign.

Normally, there should only be minor changes to the actual code
linking the systems and the Makefile compared to your current
embedding approach.

	Cheers --- Jan




More information about the PPL-devel mailing list