如何在Windows上使用LuaRocks安装lua-zlib?

How to install lua-zlib with LuaRocks on Windows?

我已经在Linux环境中用Lua编写了一个程序,它使用Lua模块ZipWriter及其依赖项(lua-zlibstruct)。我也试图发布到Windows,但是在构建lua-zlib

时遇到了问题。

我正在使用LuaRocks通过标准命令安装所有其他软件包。因此,要安装lua-zlib,我只使用了> luarocks install lua-zlib,但是它当然不起作用,因为未安装zlib本身,并且lua-zlib是对该库的绑定。

1
2
3
4
5
6
7
8
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

因此,我在该页面中找到了一个链接,用于Windows下zlib的不同下载。我下载了"除源之外的完整软件包"和"源"安装程序,并安装它们,他们在目录C:\\Program Files (x86)\\GnuWin32下创建了与zlib相关的文件夹和文件。我遵循了该错误日志提供的示例,并尝试再次运行luarocks

1
> luarocks install lua-zlib ZLIB_DIR="C:\\Program Files (x86)\\GnuWin32"

但同样,另一个错误:

1
2
3
4
5
6
7
8
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

确实,C:\\Program Files (x86)\\GnuWin32/zlib中没有文件/目录,如错误所示。由于某种原因,未安装。我想念什么?

注意:如错误日志所示,如果有用,我将mingw32-gcc作为编译器。


它应该使用静态zlib代替。为此,您可以在Github上遵循此指南。基本上,您需要

  • 已安装功能性zlib库
    从https://zlib.net下载,使用cmake生成Visual Studio解决方案(例如在c:\\\\ lib \\\\ zlib中)

    1
    cmake .. -DCMAKE_INSTALL_PREFIX=c:\\lib\\zlib

    然后使用VS中的" Release"构建类型从生成的解决方案中构建INSTALL项目。

  • 下载luarock lua-zlib:

    1
    2
    3
    4
    mkdir c:\\lib\\lua-zlib
    c:
    cd \\lib\\lua-zlib
    luarocks download lua-zlib
  • 编辑您的lua-zlib * .rockspec文件(例如,在c:\\\\ lib \\\\ lua-zlib中),
    "ZLIB_STATIC"添加到build.modules.zlib.defines
    "$(ZLIB_LIBDIR)/zlib"更改platform.windows.modules.zlib.libraries
    "$(ZLIB_LIBDIR)/zlibstatic"

  • 从本地源安装luarock(更改文件名以匹配现有文件):

    1
    2
    cd c:\\lib\\lua-zlib
    luarocks install lua-zlib*.rockspec