Subject: Re: [SWIPL] Query: Building foreign libraries in prolog.

From: Jan Wielemaker <[email-masked]>
Date: Tue, 8 Jan 2002 10:25:42 +0100

On Tue, 08 Jan 2002, [email-masked] 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.