From jan@swi.psy.uva.nl Tue Jan  8 10:41:55 2002
Received: from gollem.swi.psy.uva.nl (root@gollem.swi.psy.uva.nl [145.18.152.30])
	by swi.psy.uva.nl (8.11.6/8.11.2) with ESMTP id g089ftT20499;
	Tue, 8 Jan 2002 10:41:55 +0100 (MET)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.11.3/8.11.3/SuSE Linux 8.11.1-0.5) id g089ft013529;
	Tue, 8 Jan 2002 10:41:55 +0100
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: mfamir@hss.hns.com, prolog@swi.psy.uva.nl, xpce-users@swi.psy.uva.nl
Subject: Re: [SWIPL] Query: Building foreign libraries in prolog.
Date: Tue, 8 Jan 2002 10:25:42 +0100
X-Mailer: KMail [version 1.0.29.2]
Content-Type: text/plain
References: <65256B3B.00330C98.00@sandesh.hss.hns.com>
In-Reply-To: <65256B3B.00330C98.00@sandesh.hss.hns.com>
MIME-Version: 1.0
Message-Id: <02010810415500.13404@gollem>
Content-Transfer-Encoding: 8bit

On Tue, 08 Jan 2002, mfamir@hss.hns.com wrote:

[using a bit more uniform line-length it gets less a mess here ...]

>So, if I run "mypl" it gives me the prolog prompt with which I can execute the
>API's
>in the foreign code libraries.
>
>My question is:
>=============
>I also need the functionality of xpce along with the other functionalities of my
> libraries
>and the swi.
>Is there any way I can make the xpce also available in the same executable,
>"mypl".
>The requirement also says that xpce should be statically linked so that I can
>run the
>same exe on the platform where swi / xpce is not installed.
>
>I have an xpce version built with the static linking option i.e. swi + xpce. Can
> this built
>be of some use in achieving the same.

This issue re-appears from time to time.  If you want a true 1-file
executable you'll have to tweak the process done my `make pl-static' in
the XPCE hierarchy to create the statically linked xpce+swi (which I
wrote long ago at the time various Unix systems had problems creating or
debugging runtime-loaded dynamic libraries).

One option for for future would be to use the GNU link/compile suite
(forgotten the name) that allows for true dynamic linking as well as
static linking in one uniform framework.  It means rewriting most of the
existing Makefiles and a little bit of code.

An alternative improvement for XPCE/SWI-Prolog would be to have a
pl-config script that can produce appropriate commands and flags to
link various combinations or extend plld.

The alternative is to make sure the shared objects can be found.  One
simple way to achieve this is to ensure the system contains the code

setup_foreign_path :-
	current_prolog_flag(executable, Exe),
	file_directory_name(Exe, ExeDir),
	asserta(user:file_search_path(foreign, ExeDir)).

:- initialization setup_foreign_path.

Now you can distribute your executable and all the .so files it needs.
On the target platform put them all nicely together in one directory
and make a symbolic link from a public executable directory to the
exe (or add the new directory to $PATH).

Zillion variations on the theme are possible, for example assuming
the foreign libraries are in ../lib/ relative to the binary,
../lib/myapp/, etc.

