|
HowToJPL
Compiling SWI-Prolog for the JPL Java API
AbstractThe SWI-Prolog compiler needs to be recompiled (on most Linux distributions) for JPL to work, since JPL is not in the default-configuration and it needs libswipl compiled as a shared library. However: Online documentation indicates that recompilation may be not necessary on AMD64/x86_64 platforms. Only compiling JPL may suffice. StepsGet the source: http://www.swi-prolog.org/download/stable/src/pl-5.10.1.tar.gz Extract the tarball and edit build.templ as follows: Set PREFIX:
Make sure every one of the options above is uncommented. Then run build.templ. (Despite setting SUDO in most cases the script needs to be called as root) Afterwards there should be a "jpl.jar" in /usr/lib/swipl-5.10.1/lib and libswipl.so in /usr/lib/swipl-5.10.1/lib/i686-linux For compilation of the java-sources the jpl.jar needs to be in the Classpath and java needs to be called as "java -Djava.library.path=.:/usr/lib/swipl-5.10.1/lib/i686-linux" (path to libswpl.so) This is most easily done by using the provided "env.sh" script, called by the various run.sh scripts. When using an IDE (like Eclipse) manual work is required to set the variables (see below). Please note: While this will (probably) not overwrite any SWI-Prolog packages which were installed via package management, it will replace the symbolic links to swipl, swipl-ld and swipl-rc in /usr/bin. Tested on:
TroubleshootingMost erros when using JPL are caused by incorrectly set Classpath and java.library.path variables. "java: symbol lookup error: libjpl.so: undefined symbol: PL_is_initialised" indicates that the java.library.path does not point to libswipl. When using Eclipse you need to explicitly reference the jpl.jar. Also the "native library location" (the path to libswipl.so) must be known to Eclipse. This can be done as follows: Right-click on your project, select Properties -> Java Build Path -> Libraries. Expand the "jpl.jar"-entry, select "native library location" and give it the path to libswipl.so (most likely "/usr/lib/swipl-5.10.1/lib/i686-linux") Links |