Sweep-module.so undefined symbol: PL_version_info

Loading sweep-module entails this message error:

Loading /usr/local/lib/swipl/lib/x86_64-linux/sweep-module.so (module)…
Loading /usr/local/lib/swipl/lib/x86_64-linux/sweep-module.so (module)…done
emacs: symbol lookup error: /usr/local/lib/swipl/lib/x86_64-linux/sweep-module.so: undefined symbol: PL_version_info
Error: server did not start correctly

Hi Joseph,

Thanks for reporting, this looks like a known issue when using sweep on Linux that I’m working on alleviating. Currently the workaround is to start Emacs with libswipl.so preloaded, e.g. with:

LD_PRELOAD=/path/to/libswipl.so emacs

Afterwards sweep-module.so should be able to locate PL_version_info() and the rest of the symbols defined in libswipl.so.
Does this work for you?

Hi,

At the moment, unfortunately, this solutions fails:

Warning (initialization): An error occurred while loading ‘/home/joseph/.emacs.d/init.el’:

Symbol’s value as variable is void: LD_PRELOAD=/usr/local/lib/swipl/lib/x86_64-linux/libswipl.so

I’m using Prelude Emacs and I put this line of code in ~/.emacs.d/personal/preload

Emacs is a native executable. For LD_PRELOAD to work the environment variable needs to be set before emacs is started, e.g., best as @oskardrums describes.

Thanks Jan. The trouble is that I do not understand what I have to do exactly.
I have put in my .bashrc the following line:

export PATH=$PATH:LD_PRELOAD=/usr/local/lib/swipl/lib/x86_64-linux/libswipl.so 

the result is the same. I am used to load emacs with emacs --daemon . I also test this in a terminal :

joseph@mx:~$ LD_PRELOAD= /usr/local/lib/swipl/lib/x86_64-linux/sweep-module.so emacs
bash: /usr/local/lib/swipl/lib/x86_64-linux/sweep-module.so: Permission non accordée
joseph@mx:~$ sudo LD_PRELOAD= /usr/local/lib/swipl/lib/x86_64-linux/sweep-module.so emacs
[sudo] Mot de passe de joseph : 
sudo: /usr/local/lib/swipl/lib/x86_64-linux/sweep-module.so : commande introuvable

without success, as you can see. I am lost…

I don’t think specifying LD_PRELOAD in PATH will work. Your terminal test looks better, but there’s an extra space between the = and the path to the .so. Running LD_PRELOAD=/usr/local/lib/swipl/lib/x86_64-linux/sweep-module.so emacs should work.

Thanks for your attention, but even if that now emacs is started, finally it fails:

LD_PRELOAD=/usr/local/lib/swipl/lib/x86_64-linux/sweep-module.so emacs

emacs: symbol lookup error: /usr/local/lib/swipl/lib/x86_64-linux/sweep-module.so: undefined symbol: PL_version_info

you’re at the right direction, just preload libswipl instead of sweep-module :slight_smile:

1 Like

I use a little script in ~/bin/emacs, holding the code below. Of course you may need to update the locations. This is IMO better as it only injects Prolog into Emacs, not in all programs you run. From Emacs-29 this should no longer be needed.

#!/bin/sh
LD_PRELOAD=~/src/swipl-devel/build.pgo/src/libswipl.so /bin/emacs "$@"

Oups !! Thanks for your attention !

Many thanks Jan, thanks to all of you. It works now !

1 Like

I need the LD_PRELOAD with Emacs-29.0.50 on Debian 11 (bullseye) [ChromeBook]:

GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.16.0, Xaw3d scroll bars) of 2022-10-07

EDIT: I build SWI-prolog with -DCMAKE_INSTALL_PREFIX=$HOME/.local

Yes, the plan is to solve this (for Emacs 29+) by having sweeprolog.el explicitly load libswipl.so before loading sweep-module.so. To do that we need to tweak libswipl a bit, see Support loading libswipl as a GNU Emacs dynamic module by eshelyaron · Pull Request #1055 · SWI-Prolog/swipl-devel · GitHub (I have a couple of comments from @jan to address wrt that PR, of course further comments are very welcome).
Will update when that’s done.

LD_PRELOAD should no longer be required with the latest SWI-Prolog (thanks @jan for merging the aforementioned PR) and the latest sweep (update with M-x package-refresh-contents followed by M-x package-update sweep)

Please do report if you still have problems running without LD_PRELOAD on Emacs 29

1 Like

Looking better with each update :slight_smile: I’ve updated sweep for SWI-Prolog git tree as well. I think you can improve a little by having write_sweep_module_location/0 in the sweep.pl module return all relevant info in one pass. For example emitting two lines if we need to preload libswipl as in

/path/to/libswipl.so
/path/to/sweep-module.so

In that case you can simply load add .so files from the result, where the last one is your module. You can of course also add some indication about the role of each .so file.

Notably on Windows the startup time of Prolog is relatively long.

Will do, the current implementation is admittedly a bit hacky in that area.

I was happily surprised that on my Mac M1, starting Emacs, run

M-x pack-install RET sweeprolog RET

and all worked :slight_smile: This is a pretty much virgin Emacs installation from Macports.

P.s. That is with the SWI-Prolog built from source. It seems sweep is currently not installed properly in SWI-Prolog.app bundle :frowning:

1 Like

package-update seemed to have problems, so I did a package-delete, package-refresh-contents, package-install for sweeprolog … got this message with package-install:

Compiling file /home/peter/.emacs.d/elpa/sweeprolog-0.6.1/sweeprolog-tests.el at Thu Oct 13 09:24:18 2022
Entering directory ‘/home/peter/.emacs.d/elpa/sweeprolog-0.6.1/’
sweeprolog-tests.el:3:2: Error: Failed to locate ‘sweep-module’. Make sure SWI-Prolog is installed and up to date
Compiling file /home/peter/.emacs.d/elpa/sweeprolog-0.6.1/sweeprolog.el at Thu Oct 13 09:27:31 2022
sweeprolog.el:1910:21: Warning: ‘flymake-show-diagnostics-buffer’ is an
    obsolete function (as of 1.2.1); use ‘flymake-show-buffer-diagnostics’
    instead.

I also got this message when I set LD_PRELOAD (which had worked with the earlier version of sweeprolog). As before, I’ve installed swipl in ~/.local/bin, and it seems to run fine:

$ swipl 
Welcome to SWI-Prolog (threaded, 64 bits, version 8.5.18-39-g984787a12-DIRTY)
...
$ uname -a
Linux penguin 5.10.131-19114-g6651b07c6153 #1 SMP PREEMPT Thu Sep 1 19:07:41 PDT 2022 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye

Emacs is freshly rebuilt from source at git://git.sv.gnu.org/emacs.git 6efc64395282a960000d6fd9ac2e33ab7c764478:

GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.16.0, Xaw3d scroll bars) of 2022-10-13

(I’ll try this on Ubuntu 20.0.4 later today)

Thank you for the detailed report.
I suspect this indeed has to do with the fact that you have swipl installed in ~/.local/bin because otherwise I can’t reproduce this on a pretty similar environment.
I’ll see if I can reproduce it after installing swipl there. Would I be right to assume that you have ~/.local/bin in your PATH?

EDIT: if you could also share the cmake flags you use to configure the swipl build that would be helpful.

That’s the case, M-x sweeprolog-mode and my emacs crashes :

joseph@mx:~$ emacs --version
GNU Emacs 29.0.50

emacs: symbol lookup error: /usr/local/lib/swipl/lib/x86_64-linux/sweep-module.so: undefined symbol: PL_version_info