Re: jpl and XPCE

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 03/11/2014 01:28 AM, Sergio Castro wrote:
> Hello,
> 
> I wanted to experiment a bit with XPCE from a Java application
> embedding SWI by means of JPL.
> 
> I tried with this query: "use_module(library(lists)), gtrace,
> member(X, [1,2,3])"
> 
> In OSX, the query is frozen and I do not see any window.

I'd start a bit more modestly.  First of all, you probably need to
load swi('swipl-win.rc') (or swi('swipl.rc', which I think is the
same on MacOS; these things depend a little on the platform).  You
probably also need to set the Prolog flag

	:- set_prolog_flag(xpce_threaded, true).

This causes loading xpce to start a new thread for the event handling.

That should typically suffice to be able to run goals such as
emacs/0 to bring up PceEmacs.   Their can be additional issues if
the embedding environment also wishes to use X11.  I don't know if/how
Java accesses X11.  It may also just work and it may not.

> From a very old post I found here:
> "http://osdir.com/ml/ai.prolog.swi/2003-05/msg00045.html", I read
> that in JPL applications the scripts needed to setup XPCE are not
> called. Is that still the case in current swi versions ?
> 
> In that link, Jan recommended to execute first:
> "consult(swi('plwin.rc'))." Apparently, that file does not exist
> anymore, but I found "swipl-win.rc" that looks like its modern
> incarnation, and tried with that but it did not help.
> 
> In Ubuntu it was a bit worse, since I got this trace with errors:

Well, something happened.  Crashes are typically easier to debug than
freezing.

> ERROR: /usr/local/lib/swipl-6.6.2/xpce/prolog/boot/pce_principal.pl:141:
> '$open_shared_object'/3: /usr/local/lib/swipl-6.6.2/lib/x86_64-linux/pl2xpce.so: undefined symbol: PL_prof_exit

Hmmm.  This is a symbol provided by libswipl.so.  I think I know what
happens.  pl2xpce.so (and all other SWI-Prolog plugins) do not explicitly
depend on libswipl.so on ELF based systems because these symbols are already
around.  This allows for loading the extension without worrying about paths
or versions of SWI-Prolog.  Unfortunately, Java loads libswipl.so without
making its symbols available for future loads.  The simplest way around this
is to use

	LD_PRELOAD=/path/to/libswipl.so java arg ...

This probably applies for loading any plugin.  Note that this is not a
problem on MacOS because its binary format is XCOFF, which always requires
the library being mentioned explicitly.

	Cheers --- Jan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.