Build SWI-Prolog using Microsoft Visual Studio

The migration to CMake opens the route to build SWI-Prolog on Windows using Microsoft Visual Studio. I pushed some updates to swipl-devel that allowed me building swipl.exe for single-threaded use and without GMP. The CMake config run is

mkdir build.vs2019
cd build.vs2019
cmake -DMINGW_ROOT=z:/conan/win64 -DMULTI_THREADED=OFF -DUSE_GMP=OFF -DSWIPL_PACKAGES=OFF -DCMAKE_BUILD_TYPE=Debug -G "Visual Studio 16 2019" -A x64 ..

z:\conan\win64 is where I installed the zlib binary (dll and include), misusing the MinGW location handling for dependencies.


  • Builds swipl.exe which seems to work fine (minimal testing)
  • swipl-win.exe fails for some Windows resource handling issue.

I’m wondering whether there are people out there who wish to take this to the next level. Some of the stuff that needs to be done:

  • Think about the whole set of requirements. I considered using Conan. This deals with quite a few dependencies. Some problematic issues are GMP and ossp-uuid. Possibly more. Possibly there are better alternatives. The ports I found are in the table below.
Name Conan place Remarks
gmp gmp/6.1.2@bincrafters/stable Not for Windows
jpeg libjpeg/9c@bincrafters/stable
libffi libffi/3.2.1@bincrafters/stable
libyaml libyaml/0.2.2@bincrafters/stable
openssl OpenSSL/latest_1.1.1x@conan/stable
pcre pcre2/10.32@bincrafters/stable
pthread-win32 ?
uuid libuuid/1.0.3@bincrafters/stable Not the OSSP version
zlib zlib/1.2.11@conan/stable
  • Cleanup warnings
  • CMake configure is really slow on Windows. Bypass checks for many functions, headers, etc we know are not on Windows anyway.
  • Test, packaging, etc.

If you think this is a worthwhile exercise and you have relevant expertise, please jump in.

What is the advantage of compiling with MS Visual Studio?

I think Jan is trying to say that for those who develop on Windows, like me, and want to build the code from source, this would be a better means in some scenarios. AFAIK there would be no advantage to building on Windows with MS Visual Studio vs building on Linux, Mac.

So why would someone want to build SWI-Prolog from source on Windows using MS Visual Studio?

  1. If the build process is solid, e.g. doesn’t cause problems and can take care of problems like unresolved file locations by issuing errors and warnings, then SWI-Prolog could be built simply by downloading the source from GitHub, bringing the source into MS Visual Studio, (community version is free), and then just press F5 and get a running version of SWI-Prolog.

  2. If you want to add some low level functionality in C and don’t develop on Linux, then being able to write the low level C on Windows and then build on Windows would nice.

  3. If you build from source and leave in the debug info, then you can track down some really low level bugs. Luckily I have not had to do this yet with SWI-Prolog.

  4. Would not have to do a cross build on Linux for the Windows version.

  5. Customize the Windows version.

1 Like

Unfortunately it won’t be that smooth. SWI-Prolog has quite a few external dependencies and some of these are hard to get for Windows. I’m looking into Conan for that, but for now it only solves about half the dependencies and some are known to be nasty, notably the GMP library. The options seem to be to compile it using MinGW and adjust it for use with MSVC or depend on some unofficial code that can be compiled on MSVC.

Help is appreciated!

1 Like

In looking to do a native Windows build of RocksDB found vcpkg which has a port for RocksDB

vcpkg/ports/rocksdb at 7139d6c222641e007079059172db8998819b0bba · microsoft/vcpkg · GitHub

They also have code for the items in the noted list above.

Name vcpkg Version
bdb .\vcpkg install berkeleydb 4.8.30
gmp .\vcpkg install gmp 6.2.1
jpeg .\vcpkg install openjpeg 2.4.0
libarchive .\vcpkg install libarchive 3.5.2
libffi .\vcpkg install libffi 3.4.2
libyaml .\vcpkg install libyaml 0.2.5
openssl .\vcpkg install openssl 1.1.1n
pcre .\vcpkg install pcre2 10.39
pthread-win32 .\vcpkg install pthreads 3.0.0
uuid .\vcpkg install libuuid 1.0.3
zlib .\vcpkg install zlib 1.2.11

Have not tried any of this out but looks to be one the more likely routes to not only getting a native Windows build of SWI-Prolog but to get a native Windows build of SWI-Prolog with RocksDB and rocks-predicates using CMake with CMakeLists.txt files.


Good to know. That may make an MSVC build of the whole thing feasible. That should simplify debugging. Would be nice to see it at work. One of the reasons to switch to MinGW was that the result was about 30% faster. Would be interesting to know whether that is still the case. The other reason was to get rid of maintaining two build systems. Cmake solved that part.

1 Like

For those following along who are as naive as me when it comes to building for multiple systems (Unix/Linux, Windows, MacOS), two libraries that are widely used and easy to find source code, build files, test cases and built executables for are

zlib is a core package (not pack/add-on) of SWI-Prolog. (ref)
libffi is used with the ffi pack/add-on for SWI-Prolog. (ref)

Now have zlib building on Windows 10 using Visual Studio 2022 generating zlib1.dll without any problems. Was able to replace it with the one in C:\Program Files\swipl\bin\zlib1.dll and successfully run the SWI-Prolog zlib package tests.

Click triangle to expand for details

The first part (build) does not use SWI-Prolog and is for those who my find themselves here needing to know how to build zlib1.dll on Windows. The second part (test) is for those using SWI-Prolog and want to test zlib1.dll as used by SWI-Prolog.

Note: This does not use MinGW, MSYS2, Cygwin, GCC, Ninja, CMake or any sort of cross build.


  • Visual Studio 2022
    • There is a free edition (community) which requires one to sign up for subscription which is also free.
    • Only tried this on Windows 10.
    • Curious to know if this works with Visual Studio installed on a Mac.
  • Source code from

Building zlib1.dll on Windows

Note: As this needs a build directory to build the source code into the executables create a build directory that does not need admin permission to change files, e.g. C:\Users\Groot\zlib. In the following instructions this will be referred to as <build directory>

Note: Some commands are run first simply to get a response as a check. Sounds like a needless task but really does eliminate many problems along the way as it jogs ones memory if the check fails.

Start x64 Native Tools Command Prompt for VS 2022

   To find x64 Native Tools Command Prompt for VS 2022
   Using Windows search image enter x64 then in list above that click on

   If x64 Native Tools Command Prompt for VS 2022 can not be found odds are Visual Studio 2022 was not installed correctly.

Using x64 Native Tools Command Prompt for VS 2022

C:\Program Files\Microsoft Visual Studio\2022\Community>cd <build directory>
<build directory>> curl --version
<build directory>> curl -o zlib-1.2.12.tar.gz
<build directory>> tar --version
<build directory>> tar xzvf zlib-1.2.12.tar.gz
<build directory>> cd zlib-1.2.12
<build directory>\zlib-1.2.12> nmake /?
<build directory>\zlib-1.2.12> nmake /f win32/Makefile.msc
<build directory>\zlib-1.2.12> dir /b zlib1.dll

Testing zlib1.dll with SWI-Prolog

Note: As the SWI-Prolog zlib tests are in a git submodule need a directory to hold the SWI-Prolog package zlib repository that does not need admin permission to change files, e.g. C:\Users\Groot. In the following instructions this will be referred to as <package directory>

Using Windows Command Prompt

C:\Users\Groot> cd <package directory>
<package directory>> git --version
<package directory>> git clone
<package directory>> cd packages-zlib
<package directory>\packages-zlib> dir /B
<package directory>\packages-zlib> exit

Using SWI-Prolog

?- asserta(user:file_search_path(package,'<package directory>')).
?- use_module(package('packages-zlib/test_zlib')).
?- run_tests.

All 22 test should pass.

?- halt.

Using Windows Administrator: Command Prompt
Note: This is a command prompt started with Run as administrator

C:\WINDOWS\system32> rename "C:\Program Files\swipl\bin\zlib1.dll" "zlib1(original).dll"
C:\WINDOWS\system32> copy "<build directory>\zlib-1.2.12\zlib1.dll" "C:\Program Files\swipl\bin\zlib1.dll"

Using SWI-Prolog

?- asserta(user:file_search_path(package,'<package directory>')).
?- use_module(package('packages-zlib/test_zlib')).
?- run_tests.

All 22 test should pass.

?- halt.

Using Windows Administrator: Command Prompt

C:\WINDOWS\system32> del "C:\Program Files\swipl\bin\zlib1.dll"
C:\WINDOWS\system32> rename "C:\Program Files\swipl\bin\zlib1(original).dll" "zlib1.dll"
C:\WINDOWS\system32> exit

6 posts were split to a new topic: Want to build in Visual Studio 2019