I've written a program with Lua, in a Linux environment, and it uses the Lua module ZipWriter
and its dependecies (lua-zlib
and struct
). I'm trying to release to Windows as well, but I'm having trouble building lua-zlib
.
I'm using LuaRocks to install all other packages, with standard commands. So, to install lua-zlib
, I just used > luarocks install lua-zlib
, but of course it wouldn't work, as zlib
itself wasn't installed, and lua-zlib
is a binding to that library.
Installing https://luarocks.org/lua-zlib-1.2-0.src.rock
Error: Could not find header file for ZLIB
No file zlib.h in c:/external/include
No file zlib.h in c:/mingw/include
No file zlib.h in c:/windows/system32/include
You may have to install ZLIB in your system and/or pass ZLIB_DIR or ZLIB_INCDIR to the luarocks command.
Example: luarocks install lua-zlib ZLIB_DIR=/usr/local
So, I found a link in that page for different downloads of zlib
for Windows. I downloaded both the "Complete package, except sources" and "Sources" Setups, installed them, and they created folders and files under the directory C:\Program Files (x86)\GnuWin32
, all related to zlib
. I followed the example provided by that error log and tried running luarocks
again:
> luarocks install lua-zlib ZLIB_DIR="C:\Program Files (x86)\GnuWin32"
But again, another error:
Installing https://luarocks.org/lua-zlib-1.2-0.src.rock
mingw32-gcc -O2 -c -o lua_zlib.o -IC:\lua\luajit lua_zlib.c -DLZLIB_COMPAT -IC:\Program Files (x86)\GnuWin32/include
mingw32-gcc -shared -o zlib.dll lua_zlib.o -lC:\Program Files (x86)\GnuWin32/zlib C:\lua\luajit/lua51.dll -lMSVCRT
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lC:\Program Files (x86)\GnuWin32/zlib
collect2.exe: error: ld returned 1 exit status
Error: Build error: Failed compiling module zlib.dll
And indeed, there was no file/directory in C:\Program Files (x86)\GnuWin32/zlib
, as the error shows. For some reason, that was not installed. What am I missing?
Note: as the error log shows, I have mingw32-gcc
as the compiler, in case this is useful.
It should work using a static zlib instead. To do so, you can follow this guide on Github. Basically, you need
Functional zlib library installed
Download from https://zlib.net , use cmake
to generate Visual Studio solution (e.g. in c:\lib\zlib)
cmake .. -DCMAKE_INSTALL_PREFIX=c:\lib\zlib
then build the INSTALL project from the resulting solution, using 'Release' build type in VS.
Download luarock lua-zlib:
mkdir c:\lib\lua-zlib
c:
cd \lib\lua-zlib
luarocks download lua-zlib
Edit your lua-zlib*.rockspec file (e.g. in c:\lib\lua-zlib),
add , "ZLIB_STATIC"
to build.modules.zlib.defines
,
change platform.windows.modules.zlib.libraries
from "$(ZLIB_LIBDIR)/zlib"
to "$(ZLIB_LIBDIR)/zlibstatic"
Install the luarock from local source (change the filename to match the existing one):
cd c:\lib\lua-zlib
luarocks install lua-zlib*.rockspec