Now have zlib building on Windows 10 using Visual Studio 2022 generating zlib1.dll without any problems. Was able to replace it with the one in C:\Program Files\swipl\bin\zlib1.dll and successfully run the SWI-Prolog zlib package tests.
Click triangle to expand for details
The first part (build) does not use SWI-Prolog and is for those who my find themselves here needing to know how to build zlib1.dll on Windows. The second part (test) is for those using SWI-Prolog and want to test zlib1.dll as used by SWI-Prolog.
Note: This does not use MinGW, MSYS2, Cygwin, GCC, Ninja, CMake or any sort of cross build.
Dependencies:
-
Visual Studio 2022
- There is a free edition (community) which requires one to sign up for subscription which is also free.
- Only tried this on Windows 10.
- Curious to know if this works with Visual Studio installed on a Mac.
- Source code from https://zlib.net/zlib.net
Building zlib1.dll on Windows
Note: As this needs a build directory to build the source code into the executables create a build directory that does not need admin permission to change files, e.g. C:\Users\Groot\zlib. In the following instructions this will be referred to as <build directory>
Note: Some commands are run first simply to get a response as a check. Sounds like a needless task but really does eliminate many problems along the way as it jogs ones memory if the check fails.
Start x64 Native Tools Command Prompt for VS 2022
To find x64 Native Tools Command Prompt for VS 2022
Using Windows search
enter x64 then in list above that click on

If x64 Native Tools Command Prompt for VS 2022 can not be found odds are Visual Studio 2022 was not installed correctly.
Using x64 Native Tools Command Prompt for VS 2022
C:\Program Files\Microsoft Visual Studio\2022\Community>cd <build directory>
<build directory>> curl --version
<build directory>> curl -o zlib-1.2.12.tar.gz https://zlib.net/zlib-1.2.12.tar.gz
<build directory>> tar --version
<build directory>> tar xzvf zlib-1.2.12.tar.gz
<build directory>> cd zlib-1.2.12
<build directory>\zlib-1.2.12> nmake /?
<build directory>\zlib-1.2.12> nmake /f win32/Makefile.msc
<build directory>\zlib-1.2.12> dir /b zlib1.dll
Testing zlib1.dll with SWI-Prolog
Note: As the SWI-Prolog zlib tests are in a git submodule need a directory to hold the SWI-Prolog package zlib repository that does not need admin permission to change files, e.g. C:\Users\Groot. In the following instructions this will be referred to as <package directory>
Using Windows Command Prompt
C:\Users\Groot> cd <package directory>
<package directory>> git --version
<package directory>> git clone https://github.com/SWI-Prolog/packages-zlib.git
<package directory>> cd packages-zlib
<package directory>\packages-zlib> dir /B test_zlib.pl
<package directory>\packages-zlib> exit
Using SWI-Prolog
?- asserta(user:file_search_path(package,'<package directory>')).
?- use_module(package('packages-zlib/test_zlib')).
?- run_tests.
All 22 test should pass.
?- halt.
Using Windows Administrator: Command Prompt
Note: This is a command prompt started with Run as administrator
C:\WINDOWS\system32> rename "C:\Program Files\swipl\bin\zlib1.dll" "zlib1(original).dll"
C:\WINDOWS\system32> copy "<build directory>\zlib-1.2.12\zlib1.dll" "C:\Program Files\swipl\bin\zlib1.dll"
Using SWI-Prolog
?- asserta(user:file_search_path(package,'<package directory>')).
?- use_module(package('packages-zlib/test_zlib')).
?- run_tests.
All 22 test should pass.
?- halt.
Using Windows Administrator: Command Prompt
C:\WINDOWS\system32> del "C:\Program Files\swipl\bin\zlib1.dll"
C:\WINDOWS\system32> rename "C:\Program Files\swipl\bin\zlib1(original).dll" "zlib1.dll"
C:\WINDOWS\system32> exit