Compiling with swipl-ld on MS Windows

I don’t want to install msys but the MinGW 64 toolchain I used is the same one used in MSYS2 according to this page:

So it should work more or less the same.

I tried myself:

matth@hp UCRT64 ~/calc
$ ls
calc.cpp

matth@hp UCRT64 ~/calc
$ swipl-ld -o calc -goal true calc.cpp calc.pl -v
        eval `swipl.exe --dump-runtime-variables`
                PLBASE="c:/msys64/ucrt64/lib/swipl"
                PLARCH="x64-win64"
                PLSOEXT="dll"
                PLLIBDIR="c:/msys64/ucrt64/lib/swipl/bin/x64-win64"
                PLLIB="-lswipl"
                PLTHREADS="yes"
        g++.exe -c -D_REENTRANT -D__WINDOWS__ -D_WINDOWS -D__SWI_PROLOG__ -D__SWI_EMBEDDED__ -Ic:/msys64/ucrt64/lib/swipl/include -o calc.obj calc.cpp
        g++.exe -o calc.exe calc.obj -Lc:/msys64/ucrt64/lib/swipl/bin/x64-win64 -lswipl
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lswipl: No such file or directory
collect2.exe: error: ld returned 1 exit status
g++.exe returned code 1
        rm calc.obj
*** C:\msys64\ucrt64\bin\swipl-ld.exe exit status 1

The necessary dlls are in PLLIBDIR="c:/msys64/ucrt64/lib/swipl/lib/x64-win64", not .../bin/.... So, either PLLIBDIR must be fixed under MSYS2, or the prolog dlls have to be moved to the bin folder.

Does anyone know how to do this properly? I looked at a few other MSYS2 packages, but didn’t find any good examples.

I tend to “bin”, since it is Windows. More precisely, libswipl-9.dll/ucrt64/bin, and the dlls of the extensions to c:/msys64/ucrt64/lib/swipl/bin/x64-win64, since their rather generic names collide with other dlls in the top-level bin folder.

The location of the extension dlls is of no concern to swipl-ld. It seems it must pass -L/ucrt64/bin. I guess swipl-ld should depend on the CMake variable SWIPL_INSTALL_IN_LIB which decides whether libswipl.dll is in the Prolog tree or somewhere in the OS tree.