RTools40 is a minimalistic gcc compiler suite for building R and R packages under Windows. I tried to compile current swipl with the “UCRT” flavor of Rtools, whatever it is, but in contrast to “mingw32” and “mingw64”, it has a package libarchive.
One of the complications is that the libraries bundled with Rtools are all static, no dlls. That’s an R thing. R packages are themselves dlls under windows, but these libraries should preferably link to static dependencies. There is probably a reason for this.
- Download and install Rtools, see here RTools: Toolchains for building R and R packages from source on Windows
- The pacman repository of Rtools does not include git, so I installed git for Windows (Git - Downloading Package) and made it accessible to the path.
- in Rtools (UCRT):
pacman -Syu
- maybe do it twice:
pacman -Syu
pacman -S mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-libjpeg mingw-w64-ucrt-x86_64-libyaml mingw-w64-ucrt-x86_64-pcre mingw-w64-ucrt-x86_64-libarchive
git clone https://github.com/SWI-Prolog/swipl-devel
cd swipl-devel
git submodule update --init
mkdir build
cd build
cmake -DMINGW_ROOT=/ucrt64 -DINSTALL_DOCUMENTATION=OFF \
-DSWIPL_PACKAGES_X=OFF -DWIN32_DLLS="" \
-DLibArchive_INCLUDE_DIRS="`pkg-config --cflags-only-I libarchive`" \
-DLibArchive_LIBRARIES="`pkg-config --libs --static libarchive`" \
-DCMAKE_C_FLAGS=-DPCRE_STATIC \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local -G "MSYS Makefiles" ..
- Now wait 10 min
- If you run the command a second time, it returns within a few instances, and you can inspect the missing dependencies: libtcmalloc, libuuid, Berkeley DB, JNI, Java, qt5widgets. libuuid can, in principle, be fixed, but let’s move on.
make
(Removed the parts that have been fixed, see conversation below).
Last problem (we’re still at 98%), in crypto4pl.c:
C:/Users/matth/swipl-devel/packages/ssl/cryptolib.c:53:1: error: static declaration of 'EVP_MD_CTX_free' follows non-static declaration
53 | EVP_MD_CTX_free(EVP_MD_CTX *ctx)
I am unsure if this is due to clutter on my hard disk (see the recent topic), but I fixed it like this:
- (still in swipl-devel/build):
cd packages/ssl
-
notepad config.h
and add the following 3 lines in the beginning:
#define HAVE_EVP_MD_CTX_FREE 1
#define HAVE_X509_DIGEST 1
#define HAVE_X509_CRL_DIGEST 1
- (back in swipl-devel/build):
make
make install
- Now, fasten your seatbelts.
-
start swipl
(it works without “start”, as well, but you won’t have color)
Welcome to SWI-Prolog etc.
- ?-
member(X, [1, 2, 3]).
X = 1 ;
X = 2 ;
X = 3.
- ?-
check_installation.
% Checking your SWI-Prolog kit for common issues ...
%
% Version: ............. 8.3.28-42-gcfeb5156d-DIRTY
% Address bits: ........ 64
% Architecture: ........ x64-win64
% Installed at: ........ c:/rtools40/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:
% Supported formats: 7zip, ar, cab, cpio, empty, gnutar, iso9660, lha, mtree, rar, raw, tar, xar, zip
% Loading library(cgi) ......................... ok
% Loading library(crypt) ....................... ok
Warning: library(bdb) .......................... NOT FOUND
Warning: See http://www.swi-prolog.org/build/issues/bdb.html
% 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:/rtools40/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.
Nothing unexpected. Except that libarchive claims to support RAW and MTREE, which it doesn’t, so my pull request for packages/archive4pl.c may be wrong or not sufficient.
- Let’s see if we can compile things: ?-
pack_install(environ).
% Contacting server at https://www.swi-prolog.org/pack/query ... ok
Install environ@1.0 from http://www.swi-prolog.org/download/pack/environ-1.0.tgz Y/n?
% Contacting server at https://www.swi-prolog.org/pack/query ... ok
% "environ-1.0.tgz" was downloaded 52 times
Package: environ
Title: Demo package with C code, fetching the program environment
Installed version: 1.0
Author: Jan Wielemaker <jan@swi-prolog.org>
Home page: http://www.swi-prolog.org/howto/ForeignPack.html
Download URL: http://www.swi-prolog.org/download/pack/environ-*.tgz
Install "environ-1.0.tgz" (1,084 bytes) Y/n?
Warning: In file included from c:/rtools40/usr/local/include/SWI-Prolog.h:50,
Warning: from c/environ.c:1:
Warning: c/environ.c: In function 'pl_environ':
Warning: c/environ.c:9:17: warning: '__p__environ' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
Warning: 9 | { extern char **environ;
Warning: | ^~~~~~~
% gcc -I"c:/rtools40/usr/local/include" -c -o c/environ.o c/environ.c
% mkdir -p lib/x64-win64
% gcc -shared -L"c:/rtools40/usr/local/bin" -o lib/x64-win64/environ.dll c/environ.o -lswipl
% make: Nothing to be done for 'check'.
% make: Nothing to be done for 'install'.
true.
Good enough for now.
- ?-
use_module(library(environ)).
- ?-
environ(X).
(some stuff is shown)
Very nice.