# Compiling with swipl-ld on MS Windows

**URL:** <https://swi-prolog.discourse.group/t/compiling-with-swipl-ld-on-ms-windows/8761>\
**Category:** General\
**Created:** [January 30, 2025, 5:06pm UTC](https://swi-prolog.discourse.group/t/compiling-with-swipl-ld-on-ms-windows/8761 "2025-01-30T17:06:11Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![stassa.p](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/stassa.p/32/712_2.png) [@stassa.p](https://swi-prolog.discourse.group/u/stassa.p)\
**Post date:** [February 3, 2025, 11:44am UTC](https://swi-prolog.discourse.group/t/compiling-with-swipl-ld-on-ms-windows/8761/21 "2025-02-03T11:44:16Z")

</div>

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:

> **[Pre-built Toolchains - mingw-w64](https://www.mingw-w64.org/downloads/)**
>
> A complete runtime environment for GCC & LLVM for 32-bit (x86), 64-bit (x64), and ARM64 Windows

So it should work more or less the same.

---

<div class="post-metadata">

**Author:** ![mgondan1](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/mgondan1/32/803_2.png) [@mgondan1](https://swi-prolog.discourse.group/u/mgondan1)\
**Post date:** [February 3, 2025, 5:00pm UTC](https://swi-prolog.discourse.group/t/compiling-with-swipl-ld-on-ms-windows/8761/22 "2025-02-03T17:00:16Z")

</div>

I tried myself:

```prolog
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.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [February 3, 2025, 5:18pm UTC](https://swi-prolog.discourse.group/t/compiling-with-swipl-ld-on-ms-windows/8761/23 "2025-02-03T17:18:14Z")

</div>

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.

[Previous page](https://swi-prolog.discourse.group/t/compiling-with-swipl-ld-on-ms-windows/8761.md?page=1)
