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

我在Linux环境下使用Lua编写了一个程序,它使用Lua模块ZipWriter及其依赖项(lua-zlibstruct)。我正在尝试在Windows上发布该程序,但我无法构建lua-zlib

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

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下载。我下载了"Complete package, except sources"和"Sources" Setups,然后安装了它们,并在C:\ Program Files(x86)\ GnuWin32目录下创建了与zlib相关的文件夹和文件。我遵循错误日志提供的示例并尝试再次运行luarocks

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

但又出现了另一个错误:

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,如有用,请留意。

点赞
用户8291949
用户8291949

使用静态 zlib 应该能够解决问题。要这样做,您可以按照 Github 上的这个 指南。基本上,您需要:

  1. 安装功能性 zlib 库

    https://zlib.net 下载,使用 cmake 生成 Visual Studio 解决方案 (例如在 c:\lib\zlib 中)

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

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

  2. 下载 luarock lua-zlib:

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

  4. 从本地源安装 luarock (将文件名更改为匹配现有文件):

    cd c:\lib\lua-zlib
    luarocks install lua-zlib*.rockspec
    
2020-02-10 02:08:34