Installing swi-prolog with JPL and plUnit support

  • strict warning: Non-static method view::load() should not be called statically in /home/codecomp/public_html/ on line 906.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/codecomp/public_html/ on line 607.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/codecomp/public_html/ on line 607.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/codecomp/public_html/ on line 159.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /home/codecomp/public_html/ on line 24.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/codecomp/public_html/ on line 134.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/codecomp/public_html/ on line 134.


I'm currently playing with Prolog, plUnit and JPL (Java Prolog binding) for a postgraduate course I'm taking. I had some trouble putting all together and making it work, so I decided to write this small tutorial to remember how to do it again later and to share it just in case anyone else is also having the same problems.

First, compile swi-prolog. Ubuntu swi-prolog package does not come with plUnit included so I had to compile it from the sources. I grabbed the latest (6.2.6) tarball from:

Untar the sources (I did it on /usr/local/src) and change to the generated directory:

[dmi@cyrano]$ cd /usr/local/src/pl-6.2.6

Configure it, and don't forget to enable Prolog kernel as shared library:

[dmi@cyrano]$ ./configure --prefix=/usr/local/pl-6.2.6 --enable-shared

If you forget to turn on --enable-shared you will get unsatisfied links errors like this: "java: symbol lookup error: undefined symbol: PL_is_initialised" when trying to call some prolog code from Java. This site helped to identify and solve the problem.

Build Prolog:

[dmi@cyrano]$ make
[dmi@cyrano]$ make install

Build extra packages. This step will actually add JPL and plUnit to the base prolog installation generated by the previous make install. To build packages:

[dmi@cyrano]$ cd packages/
[dmi@cyrano]$ ./configure
[dmi@cyrano]$ make
[dmi@cyrano]$ make install

Check /usr/local/pl-6.2.6/lib/swipl-6.2.6/lib/i686-linux , you should have a file named and link named pointing to it. Also check /usr/local/pl-6.2.6/lib/swipl-6.2.6/lib/ , you should have jar named jpl.jar. If those files are in place then JPL is OK.

Then check plUnit, go to /usr/local/pl-6.2.6/lib/swipl-6.2.6/library and you should see a file named

Now lets give the Prolog/JPL install a test. Given the following prolog program


...and the following Java code:

import jpl.Query;
public class MainJPL {
  public static void main(String[] args) {
    Query q;
    q = new Query("consult('')");
    q = new Query("foo(a)");
    q = new Query("foo(b)");
    q = new Query("foo(c)");
    q = new Query("foo(X)");
    while (q.hasMoreElements()) {

If you run the program this way:

[dmi@cyrano]$ java -cp .:/usr/local/pl-6.2.6/lib/swipl-6.2.6/lib/jpl.jar
-Djava.library.path=/usr/local/pl-6.2.6/lib/swipl-6.2.6/lib/i686-linux MainJPL

You should get the following output:

% compiled 0.00 sec, 3 clauses

You can also export LD_LIBRARY_PATH=/usr/local/pl-6.2.6/lib/swipl-6.2.6/lib/i686-linux instead of using -Djava.library.path and it should also work. If you don't do this you will get an exception like this:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jpl in java.library.path
        at java.lang.ClassLoader.loadLibrary(
        at java.lang.Runtime.loadLibrary0(
        at java.lang.System.loadLibrary(
        at jpl.JPL.loadNativeLibrary(
        at jpl.fli.Prolog.<clinit>(
        at jpl.Util.textToTerm(
        at jpl.Query.<init>(
        at MainJPL.main(

Now, to test plUnit, you can use the following code:

:- use_module(library(plunit)).
:- begin_tests(some_test_suite).
test(some_test_case) :- foo(a).
:-   end_tests(some_test_suite).

And if you load and run it from the swipl console you will get:

[dmi@cyrano]$ /usr/local/pl-6.2.6/bin/swipl
Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 6.2.6)
Copyright (c) 1990-2012 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 <a href="" title=""></a> for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- [''].
%   library(option) compiled into swi_option 0.00 sec, 32 clauses
%   library(pairs) compiled into pairs 0.00 sec, 22 clauses
%  library(plunit) compiled into plunit 0.03 sec, 371 clauses
% compiled 0.03 sec, 380 clauses
?- run_tests(some_test_suite).
% PL-Unit: some_test_suite . done
% All 1 tests passed

That's all, hope it helps :)

PS: Just remembered that this site: was also useful.

Edit: If you are having errors like:

[FATAL ERROR: Not a SWI-Prolog saved state]

The problem can be a conflict between the apt installed swi-prolog and the compiled one. I removed the apt (ubuntu) installed swi-prolog and all worked well again.


I figure that if God actually does exist, He's big enough to understand an honest difference of opinion.

Isaac Asimov
via linux fortune