Did you know ... Search Documentation:
Building SWI-Prolog on MacOSX

Last updated: Oct 31, 2018, homebrew

Using Macports

Building SWI-Prolog for MacOS requires Macports. In general, the Portfiles are kept nicely up-to-date thanks to Paulo Moura. If you are a Macport user, SWI-Prolog can be installed simply using one of the commands below. The first installs the `stable' version and the second the `development' version. Note that most of the time developers are better of using the development version.

port install swi-prolog
port install swi-prolog-devel

If you like to keep nice and lean system (i.e., if you do not want Macports copies of X11, ODBC, etc), you still need to install several prerequisites. First:

  1. Xcode (can be installed as a free app from the appstore)
  2. Macports (download from http://www.macports.org/)
  3. X11. This is an OS option for Lion (10.7) and must be installed from http://xquartz.macosforge.org/landing/ for Mountain Lion (10.8).

Next, you must install the following Macport libraries:

port install gmp jpeg libarchive libiconv libmcrypt ncurses \
             openssl ossp-uuid pkgconfig readline zlib pcre libedit

Next, you can download SWI-Prolog as a source archive or using GIT. If you downloaded using GIT you must prepare the sources. If you downloaded the source archive theses steps are not needed (and in fact fail). Preparing the GIT source requires GNU autoconf from Macpors:

port install autoconf

Next, prepare by running the prepare script. Omit the --yes if you want a non-default installation.

./prepare --yes

From here, the source archive and GIT alternatives are united. You can build SWI-Prolog and all packages using the build script as follows:

cp build.templ build
<edit build, following comments>

Using Homebrew

Homebrew provides an alternative to Macports. The command below installs the latest stable version of SWI-Prolog:

brew install swi-prolog

The latest git version of SWI-Prolog can be installed with this command:

brew install swi-prolog --HEAD

(contributed by Rinke Hoekstra)

Building from source using Homebrew for dependencies

As of version 7.7.21 the SWI-Prolog sources are fully compatible for building with dependencies provided by Homebrew. The dependencies can be installed using

brew install \
     cmake \
     ninja \
     gmp \
     openssl \
     libarchive \
     readline \
     ossp-uuid \
     libyaml \
     unixodbc \
     berkeley-db \
     pcre \

Brew does not provide junit.jar which is needed to run the JPL (Java interface) tests. If you want to test this get junit.jar as described in https://github.com/junit-team/junit4/wiki/download-and-install and install in /usr/local/share/java/junit.jar.

After installing all dependencies SWI-Prolog can be build according to the generic instructions using cmake that can be found here

See also
- The Portfile
- The scripts for building a binary release as distributed through our download pages are available in a git repository. Use
git clone git://www.swi-prolog.org/home/pl/git/misc/macos-build.git