简体   繁体   English

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

[英]How to install lua-zlib with LuaRocks on Windows?

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 ).我在 Linux 环境中用 Lua 编写了一个程序,它使用 Lua 模块ZipWriter及其依赖项( lua-zlibstruct )。 I'm trying to release to Windows as well, but I'm having trouble building lua-zlib .我也在尝试发布到 Windows,但是我在构建lua-zlib遇到了问题。

I'm using LuaRocks to install all other packages, with standard commands.我正在使用 LuaRocks 安装所有其他软件包,使用标准命令。 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.所以,要安装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

So, I found a link in that page for different downloads of zlib for Windows.因此,我在该页面中找到用于 Windows 的不同zlib下载的链接 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 .我下载了“完整包,除了源”和“源”安装程序,安装了它们,他们在目录C:\\Program Files (x86)\\GnuWin32下创建了文件夹和文件,所有这些都与zlib相关。 I followed the example provided by that error log and tried running luarocks again:我按照该错误日志提供的示例并尝试再次运行luarocks

> 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.事实上,如错误所示, C:\\Program Files (x86)\\GnuWin32/zlib中没有文件/目录。 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.注意:如错误日志所示,我将mingw32-gcc作为编译器,以防万一这很有用。

It should work using a static zlib instead.它应该使用静态 zlib 来代替。 To do so, you can follow this guide on Github.为此,您可以在 Github 上按照本指南进行操作。 Basically, you need基本上,你需要

  1. Functional zlib library installed已安装功能性 zlib 库
    Download from https://zlib.net , use cmake to generate Visual Studio solution (eg in c:\\lib\\zlib)https://zlib.net下载,使用cmake生成 Visual Studio 解决方案(例如在 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.然后使用 VS 中的“Release”构建类型从生成的解决方案构建 INSTALL 项目。

  2. Download luarock lua-zlib:下载 luarock lua-zlib:

     mkdir c:\\lib\\lua-zlib c: cd \\lib\\lua-zlib luarocks download lua-zlib
  3. Edit your lua-zlib*.rockspec file (eg 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"编辑您的 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. Install the luarock from local source (change the filename to match the existing one):从本地源安装 luarock(更改文件名以匹配现有文件名):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM