Raspberry Pi

134 views
Skip to first unread message

Sam Neaves

unread,
Aug 14, 2016, 3:50:18 PM8/14/16
to SWI-Prolog
I am having trouble getting a fully working version of Swi-prolog to run on a raspberry pi.

If I try: sudo apt-get install swi-prolog I get an ancient version.

If I try :

sudo apt-add-repository ppa:swi-prolog/stable
sudo apt-get update
sudo apt-get install swi-prolog
or

sudo apt-add-repository ppa:swi-prolog/devel
sudo apt-get update
sudo apt-get install swi-prolog
I get error messages:



If I git clone and try and build the development version I get

pi@raspberrypi ~/Desktop/swipl-devel $ ./build
All submodules are up-to-date
WARNING: Cannot find documentation in man/Manual.  See README.git
WARNING: and README.doc for further information.
Your kit is prepared.
Please consult INSTALL for further instructions.
make[1]: Entering directory '/home/pi/Desktop/swipl-devel/src'
****************
Making SWI-Prolog 7.3.25 for armv6l-linux
To be installed in /usr/local/bin/swipl
make[2]: Entering directory '/home/pi/Desktop/swipl-devel/src/rc'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/pi/Desktop/swipl-devel/src/rc'
make[2]: Entering directory '/home/pi/Desktop/swipl-devel/src/libtai'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/pi/Desktop/swipl-devel/src/libtai'
cp ./SWI-Prolog.h ../include/SWI-Prolog.h
Home (libraries) in /usr/local/lib/swipl-7.3.25
gcc -rdynamic -O2 -pthread -Wl,-rpath=/usr/local/lib/swipl-7.3.25/lib/armv6l-linux    \
	-I. -I. -Wall -O2  -fno-strict-aliasing -pthread -fPIC  -o swipl-ld ./swipl-ld.c  
****************
No GIT version change
rm -f ../lib/armv6l-linux/libswipl.a
gcc -shared -O2 -o ../lib/armv6l-linux/libswipl.so.7.3.25 -Wl,-soname=libswipl.so.7.3 \
		pl-atom.o pl-wam.o pl-arith.o pl-bag.o pl-error.o pl-comp.o pl-rc.o pl-dwim.o pl-ext.o pl-flag.o pl-funct.o pl-gc.o pl-privitf.o pl-list.o pl-string.o pl-load.o pl-modul.o pl-op.o pl-prims.o pl-pro.o pl-proc.o pl-prof.o pl-read.o pl-rec.o pl-setup.o pl-sys.o pl-trace.o pl-util.o pl-wic.o pl-write.o pl-term.o pl-thread.o pl-xterm.o pl-srcfile.o pl-beos.o pl-attvar.o pl-gvar.o pl-btree.o pl-init.o pl-gmp.o pl-segstack.o pl-hash.o pl-version.o pl-codetable.o pl-supervisor.o pl-dbref.o pl-termhash.o pl-variant.o pl-copyterm.o pl-debug.o pl-cont.o pl-ressymbol.o pl-dict.o pl-trie.o pl-indirect.o pl-tabling.o os/pl-buffer.o os/pl-ctype.o os/pl-file.o os/pl-files.o os/pl-glob.o os/pl-os.o os/pl-stream.o os/pl-string.o os/pl-table.o os/pl-text.o os/pl-utf8.o os/pl-fmt.o os/pl-dtoa.o os/pl-option.o os/pl-cstack.o os/pl-codelist.o os/pl-prologflag.o os/pl-rl.o os/pl-tai.o os/pl-locale.o rc/access.o rc/build.o rc/html.o rc/util.o libtai/caltime_utc.o libtai/caltime_tai.o libtai/leapsecs_sub.o libtai/leapsecs_add.o libtai/caldate_fmjd.o libtai/caldate_mjd.o libtai/leapsecs_init.o libtai/leapsecs_read.o libtai/tai_pack.o libtai/tai_unpack.o  -rdynamic -O2 -pthread -Wl,-rpath=/usr/local/lib/swipl-7.3.25/lib/armv6l-linux  -lgmp -lrt -lreadline -lncurses -lm -lrt -ldl 
ar r ../lib/armv6l-linux/libswipl.a pl-atom.o pl-wam.o pl-arith.o pl-bag.o pl-error.o pl-comp.o pl-rc.o pl-dwim.o pl-ext.o pl-flag.o pl-funct.o pl-gc.o pl-privitf.o pl-list.o pl-string.o pl-load.o pl-modul.o pl-op.o pl-prims.o pl-pro.o pl-proc.o pl-prof.o pl-read.o pl-rec.o pl-setup.o pl-sys.o pl-trace.o pl-util.o pl-wic.o pl-write.o pl-term.o pl-thread.o pl-xterm.o pl-srcfile.o pl-beos.o pl-attvar.o pl-gvar.o pl-btree.o pl-init.o pl-gmp.o pl-segstack.o pl-hash.o pl-version.o pl-codetable.o pl-supervisor.o pl-dbref.o pl-termhash.o pl-variant.o pl-copyterm.o pl-debug.o pl-cont.o pl-ressymbol.o pl-dict.o pl-trie.o pl-indirect.o pl-tabling.o os/pl-buffer.o os/pl-ctype.o os/pl-file.o os/pl-files.o os/pl-glob.o os/pl-os.o os/pl-stream.o os/pl-string.o os/pl-table.o os/pl-text.o os/pl-utf8.o os/pl-fmt.o os/pl-dtoa.o os/pl-option.o os/pl-cstack.o os/pl-codelist.o os/pl-prologflag.o os/pl-rl.o os/pl-tai.o os/pl-locale.o rc/access.o rc/build.o rc/html.o rc/util.o libtai/caltime_utc.o libtai/caltime_tai.o libtai/leapsecs_sub.o libtai/leapsecs_add.o libtai/caldate_fmjd.o libtai/caldate_mjd.o libtai/leapsecs_init.o libtai/leapsecs_read.o libtai/tai_pack.o libtai/tai_unpack.o 
ar: creating ../lib/armv6l-linux/libswipl.a
ranlib ../lib/armv6l-linux/libswipl.a
( cd ../lib/armv6l-linux && rm -f libswipl.so && ln -s libswipl.so.7.3.25 libswipl.so )
( cd ../lib/armv6l-linux && rm -f libswipl.so.7.3 && ln -s libswipl.so.7.3.25 libswipl.so.7.3 )
gcc -rdynamic -O2 -pthread -Wl,-rpath=/usr/local/lib/swipl-7.3.25/lib/armv6l-linux   -o swipl pl-main.o -L../lib/armv6l-linux -lswipl   
../lib/armv6l-linux/libswipl.so: undefined reference to `__sync_add_and_fetch_8'
collect2: ld returned 1 exit status
Makefile:212: recipe for target 'swipl' failed
make[1]: *** [swipl] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/home/pi/Desktop/swipl-devel/src'
Makefile:22: recipe for target 'lite' failed
make: *** [lite] Error 2


Finally if I git clone and build the stable version it seems to install but does not install all the libraries.

pi@raspberrypi ~/Desktop/website $ swipl
Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 7.2.3-2-g71dd8c0)
Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- [basic_site].
ERROR: /home/pi/Desktop/website/basic_site.pl:1:
	source_sink `library(http/thread_httpd)' does not exist
Warning: /home/pi/Desktop/website/basic_site.pl:1:
	Goal (directive) failed: user:use_module(library(http/thread_httpd))
ERROR: /home/pi/Desktop/website/basic_site.pl:2:
	source_sink `library(http/http_dispatch)' does not exist
Warning: /home/pi/Desktop/website/basic_site.pl:2:
	Goal (directive) failed: user:use_module(library(http/http_dispatch))
ERROR: /home/pi/Desktop/website/basic_site.pl:3:
	source_sink `library(http/http_error)' does not exist
Warning: /home/pi/Desktop/website/basic_site.pl:3:
	Goal (directive) failed: user:use_module(library(http/http_error))
ERROR: /home/pi/Desktop/website/basic_site.pl:4:
	source_sink `library(http/html_write)' does not exist
Warning: /home/pi/Desktop/website/basic_site.pl:4:
	Goal (directive) failed: user:use_module(library(http/html_write))
ERROR: /home/pi/Desktop/website/basic_site.pl:9:
	catch/3: Undefined procedure: http_handler/3
Warning: /home/pi/Desktop/website/basic_site.pl:9:
	Goal (directive) failed: user:http_handler(/,say_hi,[])
true.
Any ideas how I can fix this? Or what I am doing wrong?


Jan Wielemaker

unread,
Aug 15, 2016, 4:10:44 AM8/15/16
to Sam Neaves, SWI-Prolog
On 08/14/2016 09:50 PM, Sam Neaves wrote:
> I am having trouble getting a fully working version of Swi-prolog to run
> on a raspberry pi.
>
> If I try: sudo apt-get install swi-prolog I get an ancient version.
>
> If I try :
>
> sudo apt-add-repository ppa:swi-prolog/stable
> sudo apt-get update
> sudo apt-get install swi-prolog
>
> or
>
> sudo apt-add-repository ppa:swi-prolog/devel
> sudo apt-get update
> sudo apt-get install swi-prolog
>
> I get error messages:
>
> W: Failed to fetch
> http://ppa.launchpad.net/swi-prolog/devel/ubuntu/dists/wheezy/main/source/Sources
> 404 Not Found W: Failed to fetch
> http://ppa.launchpad.net/swi-prolog/devel/ubuntu/dists/wheezy/main/binary-armhf/Packages
> 404 Not Found W: Failed to fetch
> http://ppa.launchpad.net/swi-prolog/stable/ubuntu/dists/wheezy/main/source/Sources
> 404 Not Found W: Failed to fetch
> http://ppa.launchpad.net/swi-prolog/stable/ubuntu/dists/wheezy/main/binary-armhf/Packages
> 404 Not Found

PPAs are for Ubuntu. With some luck they can work on other Debian based
systems but they only produce binaries for i386 and amd64.

> If I git clone and try and build the development version I get
>
> pi@raspberrypi ~/Desktop/swipl-devel $ ./build All submodules are
<...>
> undefined reference to `__sync_add_and_fetch_8' collect2: ld returned 1
> exit status Makefile:212: recipe for target 'swipl' failed make[1]: ***
> [swipl] Error 1 make[1]: *** Waiting for unfinished jobs.... make[1]:
> Leaving directory '/home/pi/Desktop/swipl-devel/src' Makefile:22: recipe
> for target 'lite' failed make: *** [lite] Error 2

Has been reported before. Doesn't reproduce for me. Config:

Pi-2
Linux raspberrypi 4.1.19-v7+ #858 SMP Tue Mar 15 15:56:00 GMT 2016
armv7l GNU/Linux
gcc version 4.9.2 (Raspbian 4.9.2-10)

Using `nm`, this seems to be caused by atomic operations in pl-proc.c.
Now the question is, is this causes by the pi model or the gcc version?
From previous half-way stopped discussion I got the impression it is
the gcc version. Mine just comes from the Raspbian download.

> Finally if I git clone and build the stable version it seems to install
> but does not install all the libraries.
>
> pi@raspberrypi ~/Desktop/website $ swipl Welcome to SWI-Prolog
> (Multi-threaded, 32 bits, Version 7.2.3-2-g71dd8c0) Copyright (c)
> 1990-2015 University of Amsterdam, VU Amsterdam SWI-Prolog comes with
> ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to
> redistribute it under certain conditions. Please visit
> http://www.swi-prolog.org for details. For help, use ?- help(Topic). or
> ?- apropos(Word). ?- [basic_site]. ERROR:
> /home/pi/Desktop/website/basic_site.pl:1 <http://basic_site.pl:1>:
> source_sink `library(http/thread_httpd)' does not exist Warning:

>
> Any ideas how I can fix this? Or what I am doing wrong?

Most likely you only installed the core system. To install the whole
lot, install the dependencies as per
http://www.swi-prolog.org/build/Debian.txt. Then run from the toplevel

cp build.templ build
<check and possibly edit build according to instructions in file>
./prepare
./build

To start again, run `make distclean`. You'll have the same issue if
you want to compile the development version (which is probably a good
idea).

Cheers --- Jan

Sam Neaves

unread,
Aug 16, 2016, 5:38:41 AM8/16/16
to Jan Wielemaker, SWI-Prolog
Thanks for the info Jan, I now (eventually!) have  it running. 

For future reference this is what I did: 

The Gcc version I had was gcc (Debian 4.6.3-14+rpi1) 4.6.3

I ran : 

sudo apt-get update

sudo apt-get dist-upgrade

I then followed this procedure to update gcc to 4.9

sudo apt-get update
sudo apt-get upgrade

Opened /etc/apt/sources.list in a editor and replaced the name wheezy with jessie.

sudo nano /etc/apt/sources.list

Then updated the package list again, to access newer jessie packages:

sudo apt-get update

now installed GCC 4.9

sudo apt-get install gcc-4.9 g++-4.9

Reverted back from Jessie to Wheezy, in /etc/apt/sources.list 

Then did another update.

sudo nano /etc/apt/sources.list
sudo apt-get update

Then removed all gcc alternatives.

sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++

Then set gcc alternatives with more priority to GCC 4.9 version.

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9
I could now build swipl-development version using the build script but I still had problems with libraries.

So I uninstalled again and then used following the instructions for separate making:


Building SWI-Prolog lite
------------------------

In normal cases, the following should do:

    % cd src
    % ./configure
    % gmake
    % gmake check
    % gmake install

By default, the system is installed   as  /usr/local/bin/swipl, with the
libraries in /usr/local/lib/swipl-<version>.  Use the `--prefix=` option
of `configure` to overrule this.

    % ./configure --prefix=PREFIX


Building the SWI-Prolog packages
--------------------------------

After building and  installing  the  core   system,  you  can  build the
extension packs:

    % cd packages
    % ./configure
    % gmake
    % gmake install

The packages can also be  configured   and  build  individually from the
package itself. Individual packages are   installed with the ./configure
&& make && make install sequence in the package directory.



And it now works :)

Jan Wielemaker

unread,
Aug 16, 2016, 7:31:01 AM8/16/16
to Sam Neaves, SWI-Prolog
Hi Sam,

Thanks. So, gcc 4.9 does the trick. Two questions:

- How come you have an old version? 4.9 seems in the standard
Raspbian image from over half a year ago.
- You say the build script doesn't work, but without details.
Would be nice to have the details, so it can be fixed.

(1) is mostly whether or not I should consider to find and
conditionally replace the 64-bit atomic instructions.

Cheers --- Jan

On 16/08/16 11:38, Sam Neaves wrote:
> Thanks for the info Jan, I now (eventually!) have it running.
>
> For future reference this is what I did:
>
> The Gcc version I had was gcc (Debian 4.6.3-14+rpi1) 4.6.3
>
> I ran :
>
> sudo apt-get update
>
>
> |sudo apt-get dist-upgrade|
>
>
> I then followed this procedure to update gcc to 4.9
>
> |sudo apt-get update sudo apt-get upgrade|
>
> Opened |/etc/apt/sources.list| in a editor and replaced the
> name |wheezy| with |jessie|.
>
> |sudo nano /etc/apt/sources.list|
>
> Then updated the package list again, to access newer jessie packages:
>
> |sudo apt-get update|
>
> now installed GCC 4.9
>
> |sudo apt-get install gcc-4.9 g++-4.9|
>
> Reverted back from |Jessie| to |Wheezy|, in |/etc/apt/sources.list|
> <http://basic_site.pl:1> <http://basic_site.pl:1>:
> source_sink `library(http/thread_httpd)' does not exist Warning:
>
>
>
> Any ideas how I can fix this? Or what I am doing wrong?
>
>
> Most likely you only installed the core system. To install the
> whole lot, install the dependencies as per
> http://www.swi-prolog.org/build/Debian.txt
> <http://www.swi-prolog.org/build/Debian.txt>. Then run from the

Sam Neaves

unread,
Aug 16, 2016, 8:49:32 AM8/16/16
to Jan Wielemaker, SWI-Prolog
I guess like a few people I had a raspberry pi sat around not being used, then I thought I could use it for some things so got it out of the dusty draw and tried to start the project!
As it started up I didn't consider downloading a new image.

So before I updated gcc, the error I had with swipl-devel is what I put in the original email.

When I updated the gcc the build script would run and I could start swipl but it had not loaded the libraries. So I would get errors like 
goal (directive) failed: user:use_module(library(http/html_write)) etc

If I understand correctly, by default the build script should install the libraries automatically? 

Jan Wielemaker

unread,
Aug 16, 2016, 9:17:22 AM8/16/16
to Sam Neaves, SWI-Prolog
On 16/08/16 14:49, Sam Neaves wrote:
> When I updated the gcc the build script would run and I could start
> swipl but it had not loaded the libraries. So I would get errors like
> goal (directive) failed: user:use_module(library(http/html_write)) etc

This was using ./build created from build.templ?

> If I understand correctly, by default the build script should install
> the libraries automatically?

The whole idea behind is that it contains the possibly necessary
localization such as installation location and enabled/disabled
extensions, compiler flags, etc.

Without editing, it will typically build a fine system in $HOME/bin,
including all libraries that by default come with the binary
distributions. It will try to skip extensions for which dependencies
are missing.

If it didn't install (some of) the libraries, it probably failed due
to some missing dependency. If you just install the ones listed in
http://www.swi-prolog.org/build/Debian.txt you should be fine. It
logs the output in some files (configure.out make-install.out
make.out), so you can search for error: or something like that to
see what went wrong.

For me, all that worked fine on a Pi-2 with an image from early
2016.

Cheers --- Jan

Jan Wielemaker

unread,
Aug 16, 2016, 4:02:55 PM8/16/16
to Sam Neaves, SWI-Prolog
Dear Sam,

FYI: I did a little more investigation. It turns out that SWI-Prolog
7.3.x requires 64-bit atomic instructions for managing the global
database generation. Older versions (7.2.x) used locked operations. 64
bit atomic operations for ARM on Linux are supported as of GCC 4.8,
which uses a kernel hack that prevent preempting between the
instructions for the single core Pi-1 and proper CPU support for later
models.

Using the Debian Jessie (8.0) based images you get gcc 4.9 or later.

At this moment I see little reason to add support for systems that do
not provide 64-bit atomic operations. If really needed I'm sure
someone can figure out a kludge. If all fails using full locks.

Cheers --- Jan


On 08/16/2016 11:38 AM, Sam Neaves wrote:
> Thanks for the info Jan, I now (eventually!) have it running.
>
> For future reference this is what I did:
>
> The Gcc version I had was gcc (Debian 4.6.3-14+rpi1) 4.6.3
>
> I ran :
>
> sudo apt-get update
>
>
> |sudo apt-get dist-upgrade|
>
>
> I then followed this procedure to update gcc to 4.9
>
> |sudo apt-get update sudo apt-get upgrade|
>
> Opened |/etc/apt/sources.list| in a editor and replaced the
> name |wheezy| with |jessie|.
>
> |sudo nano /etc/apt/sources.list|
>
> Then updated the package list again, to access newer jessie packages:
>
> |sudo apt-get update|
>
> now installed GCC 4.9
>
> |sudo apt-get install gcc-4.9 g++-4.9|
>
> Reverted back from |Jessie| to |Wheezy|, in |/etc/apt/sources.list|
> <http://basic_site.pl:1> <http://basic_site.pl:1>:
> source_sink `library(http/thread_httpd)' does not exist Warning:
>
>
>
> Any ideas how I can fix this? Or what I am doing wrong?
>
>
> Most likely you only installed the core system. To install the
> whole lot, install the dependencies as per
> http://www.swi-prolog.org/build/Debian.txt
> <http://www.swi-prolog.org/build/Debian.txt>. Then run from the

Sam Neaves

unread,
Aug 17, 2016, 9:01:27 AM8/17/16
to Jan Wielemaker, SWI-Prolog
Hi Jan,

Thanks for looking into this. I don't really understand the problem that you describe, but I wouldn't worry about it for my case. I am just building toy projects, so I just needed to figure out how to get it to work. At least now the mailbox has a record of what I did for anyone else who runs into the same or similar problem with a raspberry pi. i.e. that they could try and upgrade their gcc version and run the two separate make steps rather than the build script.   

Thanks once again,
Sam
Reply all
Reply to author
Forward
0 new messages