RTools42 is a gcc compiler suite for building R and R packages under Windows. I tried to compile current swipl with the “UCRT” flavor of Rtools, this is how it works:
- Download RTools42 from https://www.r-project.org/nosvn/winutf8/ucrt3, the name of the file was rtools42-4911-4849.exe today.
- 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 c:\rtools42, start ucrt64
- A shell appears, type
pacman -Syu
- Then
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 mingw-w64-ucrt-x86_64-db
git clone https://github.com/SWI-Prolog/swipl-devel
cd swipl-devel
git submodule update --init
mkdir build
cd build
export PATH=$PATH:/x86_64-w64-mingw32.static.posix/bin
cmake -DSWIPL_PACKAGES_X=OFF\
-DINSTALL_DOCUMENTATION=OFF\
-DMINGW_ROOT=/ucrt64\
-DHAVE_ARCHIVE_READ_SUPPORT_FORMAT_CPIO=0\
-DCMAKE_C_FLAGS=-D__USE_MINGW_ANSI_STDIO\
-G "MSYS Makefiles"\
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local ..
Then
make
make install
-
start swipl
(it works without “start”, as well, but you won’t have color) - check_installation.
Welcome to SWI-Prolog (threaded, 64 bits, version 8.5.3-25-g01ba6464b-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).
check_installation.
% Checking your SWI-Prolog kit for common issues ...
%
% Version: ............. 8.5.3-25-g01ba6464b-DIRTY
% Address bits: ........ 64
% Architecture: ........ x64-win64
% Installed at: ........ c:/rtools42/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) ..................... FAILEDc:/rtools42/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(...,_4896)))
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:/rtools42/usr/local/boot/init.pl:811
Warning: [54] catch(system:'$run_init_goal'(...),_5052,system:'$initialization_error'(_5074,...,...)) at c:/rtools42/usr/local/boot/init.pl:562
Warning: [53] catch_with_backtrace(system:'$run_init_goal'(...),_5120,system:'$initialization_error'(_5142,...,...)) at c:/rtools42/usr/local/boot/init.pl:629
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) ......................... FAILEDc:/rtools42/usr/local/library/bdb.pl:60: 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(...,_20224)))
Warning: [59] <meta call>
Warning: [58] with_mutex('$foreign',load_foreign_library(foreign(bdb4pl),bdb,default(install))) <foreign>
Warning: [55] '$run_init_goal'('<garbage_collected>') at c:/rtools42/usr/local/boot/init.pl:811
Warning: [54] catch(system:'$run_init_goal'(...),_20370,system:'$initialization_error'(_20392,...,...)) at c:/rtools42/usr/local/boot/init.pl:562
Warning: [53] catch_with_backtrace(system:'$run_init_goal'(...),_20438,system:'$initialization_error'(_20460,...,...)) at c:/rtools42/usr/local/boot/init.pl:629
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 bdb:bdb_del/3 is not defined
Warning: Exported procedure bdb:bdb_open/4 is not defined
Warning: Exported procedure bdb:bdb_put/3 is not defined
Warning: Exported procedure bdb:bdb_close/1 is not defined
Warning: Exported procedure bdb:bdb_transaction/1 is not defined
Warning: Exported procedure bdb:bdb_init/1 is not defined
Warning: Exported procedure bdb:bdb_init/2 is not defined
Warning: Exported procedure bdb:bdb_close_environment/1 is not defined
Warning: Exported procedure bdb:bdb_version/1 is not defined
Warning: Exported procedure bdb:bdb_transaction/2 is not defined
Warning: Exported procedure bdb:bdb_getall/3 is not defined
Warning: Exported procedure bdb:bdb_enum/3 is not defined
Warning: Exported procedure bdb:bdb_get/3 is not defined
Warning:
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:/rtools42/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 5 issues.
true.
The “archive” and the “bdb” problems disappear if the missing dlls (things like libbz2-1.dll that is used by bdb4pl.dll) are copied into the installation folder, /usr/local/bin. I don’t understand why they are not loaded from their default place, /ucrt/bin. If someone can explain to me how to fix this, it’s much appreciated.
cd /usr/local/bin
cp `ldd archive4pl.dll |grep -o "/ucrt64/bin/.*\\.dll"` .
cp `ldd bdb4pl.dll |grep -o "/ucrt64/bin/.*\\.dll"` .
The compiler flag -D__USE_MINGW_ANSI_STDIO
is needed to enable things like printf("%lld", (int64_t) x)
. There’s probably a way to autodetect this.