Compiling with MSYS2

Dear list, dear Jan,

I tried to compile SWI-Prolog with MSYS2 on Windows (to be more precise, MinGW64 by MSYS2). The process hangs during cmake, complaining that zlib*.dll is not found. It’s strange, since it is there:

Matthias@DESKTOP-A2T8IFC MINGW64 ~/swipl-devel/build
$ ls /bin/zlib1.dll
/bin/zlib1.dll

Matthias@DESKTOP-A2T8IFC MINGW64 ~/swipl-devel/build
$ rm -rf *

Matthias@DESKTOP-A2T8IFC MINGW64 ~/swipl-devel/build
$ cmake -G “MSYS Makefiles” …
– The C compiler identification is GNU 10.2.0
– The CXX compiler identification is GNU 10.2.0
– Check for working C compiler: C:/msys2/mingw64/bin/gcc.exe
– Check for working C compiler: C:/msys2/mingw64/bin/gcc.exe - works
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Detecting C compile features
– Detecting C compile features - done
– Check for working CXX compiler: C:/msys2/mingw64/bin/g++.exe
– Check for working CXX compiler: C:/msys2/mingw64/bin/g++.exe - works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Detecting CXX compile features
– Detecting CXX compile features - done
– Setting build type to ‘RelWithDebInfo’ as none was specified.
– Configuring SWI-Prolog-8.3.23
– Finding required external DLLs
– zlib*.dll:
CMake Error at cmake/port/Windows.cmake:36 (message):
Cannot file /bin/zlib*.dll
Call Stack (most recent call first):
cmake/port/Windows.cmake:59 (find_file_from_pattern)
cmake/port/Windows.cmake:68 (find_windows_dlls)
cmake/Ports.cmake:4 (include)
CMakeLists.txt:71 (include)

– Configuring incomplete, errors occurred!
See also “C:/msys2/home/Matthias/swipl-devel/build/CMakeFiles/CMakeOutput.log”.

Matthias@DESKTOP-A2T8IFC MINGW64 ~/swipl-devel/build
$

The use case will actually be RTools, the compiler environment for the R system, so that R packages can connect to swipl.

Best wishes,

Matthias

Its clear what is going wrong (can’t find zlib*.dll). I have little clue why though. I understood building the core has worked for some people on Windows. All I can advice is to put some additional message() calls in e.g. function find_file_from_pattern in Windows.cmake. Note that typically just running cmake .. is enough to test with the changes.

I guess it is no option for R, but building from source is a nightmare on Windows due to the large number of dependencies. That is why there is GitHub - SWI-Prolog/docker-swipl-build-mingw: Docker to cross-compile SWI-Prolog for Windows

MINGW_ROOT does not seem to be defined under MSYS2/MinGW64. Hence, this:

cmake -DMINGW_ROOT=/mingw64 -DINSTALL_DOCUMENTATION=OFF -DCMAKE_INSTALL_PREFIX:PATH=/usr/local -G “MSYS Makefiles” …

I had to do three more things to make „make“ work, as well as „make install“.

  • Some problem occurred during „make“ with pldoc (see the -DINSTALL_DOCUMENTATION=OFF). Not so important.
  • Error message during xpce (so I removed the folder packages/xpce). Not so important either.
  • I added -DCMAKE_INSTALL_PREFIX:PATH=/usr/local so that swipl is not installed into „C:\Program Files\swipl“ and so on.
  • And there’s no prompt :blush:, see below. [If you type “start swipl” instead of just swipl, the prompt is there]

Thank you! Great system, and no nightmare (anymore).

Best wishes,

Matthias

Matthias@DESKTOP-A2T8IFC MINGW64 ~/swipl-devel/demo

$ start swipl

Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.24-3-g32f8079a1-DIRTY)

SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org

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

consult(likes).

true.

likes(sam, X).

X = dahl ;

X = tandoori ;

X = kurma ;

X = chow_mein ;

X = chop_suey ;

X = sweet_and_sour ;

X = pizza ;

X = spaghetti ;

X = chips.

1 Like

OK, here’s the MSYS2 installation:

  • install msys2 from msys2.org
  • pacman -Syu
  • pacman -Syu
  • pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake git make mingw-w64-x86_64-libjpeg mingw-w64-x86_64-xpm-nox mingw-w64-x86_64-libyaml mingw-w64-x86_64-diffutils mingw-w64-x86_64-pcre mingw-w64-x86_64-db libdb-devel
  • ftp: download libuuid-1.6.2.tar.gz from ftp (dot) ossp (dot) org/pkg/lib/uuid/, configure --prefix=/usr/local, make, make install, ignore the error relating to strip.exe
  • git clone https://github.com/SWI-Prolog/swipl-devel.git
  • cd swipl-devel
  • git submodule update --init
  • mkdir build
  • cd build
  • cmake -DMINGW_ROOT=/mingw64 -DLIBUUID_INCLUDE_DIR=/usr/local/include -DUUID_LIBRARY=/usr/local/lib/libuuid.a -DBDB_LIBRARY=/mingw64/bin/libdb-6.0.dll -DINSTALL_DOCUMENTATION=OFF -DSWIPL_PACKAGES_X=OFF -DCMAKE_INSTALL_PREFIX:PATH=/usr/local -G “MSYS Makefiles” …
  • only dot dot in the previous line, and avoid “typographic” quotation marks
  • make
  • make install
  • start swipl

@Jan, please consider removing the description from the webpage (with mingw under windows)

https://www.swi-prolog.org/build/MinGW.txt

Since this is now really outdated.

1 Like

Why not update? Before doing so, how complete is the resulting system? I don’t see any of the dependencies mentioned except for libjpeg mingw-w64-x86_64-xpm-nox, both of which are needed for building xpce, but that is omitted from the build. What do you get from

?- check_installation.

I added a few packages and compiler switches, four issues left. And I agree, it is still a nightmare with the dependencies.

% Checking your SWI-Prolog kit for common issues ...
%
% Version: ............. 8.3.24-29-g24cbf084b-DIRTY
% Address bits: ........ 64
% Architecture: ........ x64-win64
% Installed at: ........ c:/msys64/usr/local
% Cores: ............... 4
%
% Checking tcmalloc ............................ not present
Warning: See http://www.swi-prolog.org/build/issues/tcmalloc.html
% Checking gmp ................................. ok
% Loading library(archive) ..................... FAILED
c:/msys64/usr/local/library/archive.pl:96:       Initialization goal raised exception:
Warning: Das angegebene Modul wurde nicht gefunden.
Warning: In:
Warning:   [61] throw(error(shared_object(open,'Das angegebene Modul wurde nicht gefunden.\r   \n'),context(...,_4132)))
Warning:   [59] <meta call>
Warning:   [58]    with_mutex('$foreign',load_foreign_library(foreign(archive4pl),archive,default(install))) <foreign>
Warning:   [55] '$run_init_goal'(shlib:load_foreign_library(...)) at c:/msys64/usr/local/boot/init.pl:796
Warning:   [54] catch(system:'$run_init_goal'(...),_4288,system:'$initialization_error'(_4310,...,...)) at c:/msys64/usr/local/boot/init.pl:546
Warning:   [53]    catch_with_backtrace(system:'$run_init_goal'(...),_4356,system:'$initialization_error'(_4378,...,...)) at    c:/msys64/usr/local/boot/init.pl:614
Warning:
Warning: Note: some frames are missing due to last-call optimization.
Warning: Re-run your program in debug mode (:- debug.) to get more detail.
Warning: Exported procedure archive:archive_set_header_property/2 is not defined
Warning: Exported procedure archive:archive_open_entry/2 is not defined
Warning: Exported procedure archive:archive_next_header/2 is not defined
Warning: Exported procedure archive:archive_close/1 is not defined
Warning: Warning: See http://www.swi-prolog.org/build/issues/archive.html
% Loading library(cgi) ......................... ok
% Loading library(crypt) ....................... ok
% Loading library(bdb) ......................... ok
% Loading library(double_metaphone) ............ ok
% Loading library(filesex) ..................... ok
% Loading library(http/http_stream) ............ ok
% Loading library(http/json) ................... ok
% Loading library(http/jquery) ................. ok
%   jQuery from c:/msys64/usr/local/library/http/web/js/jquery-1.11.3.min.js
% Loading library(isub) ........................ ok
Warning: library(jpl) .......................... NOT FOUND
Warning: See http://www.swi-prolog.org/build/issues/jpl.html
% Loading library(memfile) ..................... ok
% Loading library(odbc) ........................ ok
Warning: library(pce) .......................... NOT FOUND
Warning: See http://www.swi-prolog.org/build/issues/xpce.html
% Loading library(pcre) ........................ ok
% Loading library(pdt_console) ................. ok
% Loading library(porter_stem) ................. ok
% Loading library(process) ..................... ok
% Loading library(protobufs) ................... ok
% Loading library(readutil) .................... ok
% Loading library(semweb/rdf_db) ............... ok
% Loading library(semweb/rdf_ntriples) ......... ok
% Loading library(semweb/turtle) ............... ok
% Loading library(sgml) ........................ ok
% Loading library(sha) ......................... ok
% Loading library(snowball) .................... ok
% Loading library(socket) ...................... ok
% Loading library(ssl) ......................... ok
% Loading library(crypto) ...................... ok
% Loading library(table) ....................... ok
% Loading library(time) ........................ ok
% Loading library(unicode) ..................... ok
% Loading library(uri) ......................... ok
% Loading library(uuid) ........................ ok
% Loading library(zlib) ........................ ok
% Loading library(yaml) ........................ ok
Warning: Found 4 issues.
true.

Funny enough, the trouble with libarchive disappeared with debug.

debug.
check_installation.
% Checking your SWI-Prolog kit for common issues ...
%
% Version: ............. 8.3.24-29-g24cbf084b-DIRTY
% Address bits: ........ 64
% Architecture: ........ x64-win64
% Installed at: ........ c:/msys64/usr/local
% Cores: ............... 4
%
% Checking tcmalloc ............................ not present
Warning: See http://www.swi-prolog.org/build/issues/tcmalloc.html
% Checking gmp ................................. ok
% Loading library(archive) ..................... ok
%   Supported filters: bzip2, compress, gzip, grzip, lrzip, lzip, lzma, lzop, none, rpm, uu, xz
%   Supported formats: 7zip, ar, cab, cpio, empty, gnutar, iso9660, lha, mtree, rar, raw, tar, xar, zip
% Loading library(cgi) ......................... ok

etc., the other messages stay the same.

1 Like

Thanks. No real clue about why debug should make a difference wrt loading libarchive!? Updated the page, copying the above and referring to this post. Note that you can propose changes to the static pages of the website using PRs on GitHub - SWI-Prolog/plweb-www: Submodule of plweb.git that contains the (wiki) web-pages

Did the same with MSYS2/mingw32: works fine, no changes except for i686 in the pacman package names instead of x86_64.

Ok, I found the problem with libarchive, the dlls for the different compression formats were not found. If I copy them into the installation folder /usr/local/bin, check_installation works.

cd /usr/local/bin
cp `ldd libarchive-13.dll |grep -o "/mingw64/bin/.*\\.dll"` .

If someone knows a better way to fix this problem, please let me know.
check_installation complains about 3 more issues, these are related to tcmalloc, xpce, java—none of them are found on a msys2/mingw64 system, so this is expected behavior.