【问题标题】:Compiling Luasocket编译 Luasocket
【发布时间】:2026-02-18 14:10:02
【问题描述】:

所以我正在尝试将 Luasocket 与具有 Lua API 的第三方游戏一起使用。它支持包,但它说它需要一些我没有的 luasocket 文件(尽管它在 IDE 之外工作,因为我在 lua 目录中安装了 Luasocket)。这些似乎是 core.dll、core.lua 和 core/init.lua。我假设我通过编译 Luasocket 得到了这些。

我尝试过,但收效甚微。我发现用于构建 luasocket 的脚本总是给我错误。我应该如何获取这些文件并编译它们?

编辑:这是我尝试构建 Luasocket 时 Cygwin 给我的错误:

src/wsocket.c: In function ‘socket_open’:
src/wsocket.c:19:5: error: unknown type name ‘WSADATA’
     WSADATA wsaData;
     ^
src/wsocket.c:20:5: error: unknown type name ‘WORD’
     WORD wVersionRequested = MAKEWORD(2, 0);
     ^
src/wsocket.c:23:24: error: request for member ‘wVersion’ in something not a structure or union
     if ((LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 0) &&
                        ^
src/wsocket.c:23:57: error: request for member ‘wVersion’ in something not a structure or union
     if ((LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 0) &&
                                                         ^
src/wsocket.c:24:24: error: request for member ‘wVersion’ in something not a structure or union
         (LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1)) {
                        ^
src/wsocket.c:24:57: error: request for member ‘wVersion’ in something not a structure or union
         (LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1)) {
                                                         ^
src/wsocket.c: In function ‘socket_select’:
src/wsocket.c:82:16: error: ‘DWORD’ undeclared (first use in this function)
         Sleep((DWORD) (1000*t));
                ^
src/wsocket.c:82:16: note: each undeclared identifier is reported only once for each function it appears in
src/wsocket.c: In function ‘socket_connect’:
src/wsocket.c:127:16: error: ‘WSAEWOULDBLOCK’ undeclared (first use in this function)
     if (err != WSAEWOULDBLOCK && err != WSAEINPROGRESS) return err;
                ^
src/wsocket.c:127:41: error: ‘WSAEINPROGRESS’ undeclared (first use in this function)
     if (err != WSAEWOULDBLOCK && err != WSAEINPROGRESS) return err;
                                         ^
src/wsocket.c: In function ‘socket_accept’:
src/wsocket.c:180:20: error: ‘WSAEWOULDBLOCK’ undeclared (first use in this function)
         if (err != WSAEWOULDBLOCK && err != WSAECONNABORTED) return err;
                    ^
src/wsocket.c:180:45: error: ‘WSAECONNABORTED’ undeclared (first use in this function)
         if (err != WSAEWOULDBLOCK && err != WSAECONNABORTED) return err;
                                             ^
src/wsocket.c: In function ‘socket_send’:
src/wsocket.c:211:20: error: ‘WSAEWOULDBLOCK’ undeclared (first use in this function)
         if (err != WSAEWOULDBLOCK) return err;
                    ^
src/wsocket.c: In function ‘socket_sendto’:
src/wsocket.c:233:20: error: ‘WSAEWOULDBLOCK’ undeclared (first use in this function)
         if (err != WSAEWOULDBLOCK) return err;
                    ^
src/wsocket.c: In function ‘socket_recv’:
src/wsocket.c:259:20: error: ‘WSAEWOULDBLOCK’ undeclared (first use in this function)
         if (err != WSAEWOULDBLOCK) {
                    ^
src/wsocket.c:260:24: error: ‘WSAECONNRESET’ undeclared (first use in this function)
             if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
                        ^
src/wsocket.c: In function ‘socket_recvfrom’:
src/wsocket.c:288:20: error: ‘WSAEWOULDBLOCK’ undeclared (first use in this function)
         if (err != WSAEWOULDBLOCK) {
                    ^
src/wsocket.c:289:24: error: ‘WSAECONNRESET’ undeclared (first use in this function)
             if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
                        ^
src/wsocket.c: In function ‘socket_hoststrerror’:
src/wsocket.c:333:14: error: ‘WSAHOST_NOT_FOUND’ undeclared (first use in this function)
         case WSAHOST_NOT_FOUND: return "host not found";
              ^
src/wsocket.c: In function ‘socket_strerror’:
src/wsocket.c:341:14: error: ‘WSAEADDRINUSE’ undeclared (first use in this function)
         case WSAEADDRINUSE: return "address already in use";
              ^
src/wsocket.c:342:14: error: ‘WSAECONNREFUSED’ undeclared (first use in this function)
         case WSAECONNREFUSED: return "connection refused";
              ^
src/wsocket.c:343:14: error: ‘WSAEISCONN’ undeclared (first use in this function)
         case WSAEISCONN: return "already connected";
              ^
src/wsocket.c:344:14: error: ‘WSAEACCES’ undeclared (first use in this function)
         case WSAEACCES: return "permission denied";
              ^
src/wsocket.c:345:14: error: ‘WSAECONNABORTED’ undeclared (first use in this function)
         case WSAECONNABORTED: return "closed";
              ^
src/wsocket.c:346:14: error: ‘WSAECONNRESET’ undeclared (first use in this function)
         case WSAECONNRESET: return "closed";
              ^
src/wsocket.c:347:14: error: ‘WSAETIMEDOUT’ undeclared (first use in this function)
         case WSAETIMEDOUT: return "timeout";
              ^
src/wsocket.c: In function ‘wstrerror’:
src/wsocket.c:359:14: error: ‘WSAEINTR’ undeclared (first use in this function)
         case WSAEINTR: return "Interrupted function call";
              ^
src/wsocket.c:360:14: error: ‘WSAEACCES’ undeclared (first use in this function)
         case WSAEACCES: return "Permission denied";
              ^
src/wsocket.c:361:14: error: ‘WSAEFAULT’ undeclared (first use in this function)
         case WSAEFAULT: return "Bad address";
              ^
src/wsocket.c:362:14: error: ‘WSAEINVAL’ undeclared (first use in this function)
         case WSAEINVAL: return "Invalid argument";
              ^
src/wsocket.c:363:14: error: ‘WSAEMFILE’ undeclared (first use in this function)
         case WSAEMFILE: return "Too many open files";
              ^
src/wsocket.c:364:14: error: ‘WSAEWOULDBLOCK’ undeclared (first use in this function)
         case WSAEWOULDBLOCK: return "Resource temporarily unavailable";
              ^
src/wsocket.c:365:14: error: ‘WSAEINPROGRESS’ undeclared (first use in this function)
         case WSAEINPROGRESS: return "Operation now in progress";
              ^
src/wsocket.c:366:14: error: ‘WSAEALREADY’ undeclared (first use in this function)
         case WSAEALREADY: return "Operation already in progress";
              ^
src/wsocket.c:367:14: error: ‘WSAENOTSOCK’ undeclared (first use in this function)
         case WSAENOTSOCK: return "Socket operation on nonsocket";
              ^
src/wsocket.c:368:14: error: ‘WSAEDESTADDRREQ’ undeclared (first use in this function)
         case WSAEDESTADDRREQ: return "Destination address required";
              ^
src/wsocket.c:369:14: error: ‘WSAEMSGSIZE’ undeclared (first use in this function)
         case WSAEMSGSIZE: return "Message too long";
              ^
src/wsocket.c:370:14: error: ‘WSAEPROTOTYPE’ undeclared (first use in this function)
         case WSAEPROTOTYPE: return "Protocol wrong type for socket";
              ^
src/wsocket.c:371:14: error: ‘WSAENOPROTOOPT’ undeclared (first use in this function)
         case WSAENOPROTOOPT: return "Bad protocol option";
              ^
src/wsocket.c:372:14: error: ‘WSAEPROTONOSUPPORT’ undeclared (first use in this function)
         case WSAEPROTONOSUPPORT: return "Protocol not supported";
              ^
src/wsocket.c:373:14: error: ‘WSAESOCKTNOSUPPORT’ undeclared (first use in this function)
         case WSAESOCKTNOSUPPORT: return "Socket type not supported";
              ^
src/wsocket.c:374:14: error: ‘WSAEOPNOTSUPP’ undeclared (first use in this function)
         case WSAEOPNOTSUPP: return "Operation not supported";
              ^
src/wsocket.c:375:14: error: ‘WSAEPFNOSUPPORT’ undeclared (first use in this function)
         case WSAEPFNOSUPPORT: return "Protocol family not supported";
              ^
src/wsocket.c:376:14: error: ‘WSAEAFNOSUPPORT’ undeclared (first use in this function)
         case WSAEAFNOSUPPORT:
              ^
src/wsocket.c:378:14: error: ‘WSAEADDRINUSE’ undeclared (first use in this function)
         case WSAEADDRINUSE: return "Address already in use";
              ^
src/wsocket.c:379:14: error: ‘WSAEADDRNOTAVAIL’ undeclared (first use in this function)
         case WSAEADDRNOTAVAIL: return "Cannot assign requested address";
              ^
src/wsocket.c:380:14: error: ‘WSAENETDOWN’ undeclared (first use in this function)
         case WSAENETDOWN: return "Network is down";
              ^
src/wsocket.c:381:14: error: ‘WSAENETUNREACH’ undeclared (first use in this function)
         case WSAENETUNREACH: return "Network is unreachable";
              ^
src/wsocket.c:382:14: error: ‘WSAENETRESET’ undeclared (first use in this function)
         case WSAENETRESET: return "Network dropped connection on reset";
              ^
src/wsocket.c:383:14: error: ‘WSAECONNABORTED’ undeclared (first use in this function)
         case WSAECONNABORTED: return "Software caused connection abort";
              ^
src/wsocket.c:384:14: error: ‘WSAECONNRESET’ undeclared (first use in this function)
         case WSAECONNRESET: return "Connection reset by peer";
              ^
src/wsocket.c:385:14: error: ‘WSAENOBUFS’ undeclared (first use in this function)
         case WSAENOBUFS: return "No buffer space available";
              ^
src/wsocket.c:386:14: error: ‘WSAEISCONN’ undeclared (first use in this function)
         case WSAEISCONN: return "Socket is already connected";
              ^
src/wsocket.c:387:14: error: ‘WSAENOTCONN’ undeclared (first use in this function)
         case WSAENOTCONN: return "Socket is not connected";
              ^
src/wsocket.c:388:14: error: ‘WSAESHUTDOWN’ undeclared (first use in this function)
         case WSAESHUTDOWN: return "Cannot send after socket shutdown";
              ^
src/wsocket.c:389:14: error: ‘WSAETIMEDOUT’ undeclared (first use in this function)
         case WSAETIMEDOUT: return "Connection timed out";
              ^
src/wsocket.c:390:14: error: ‘WSAECONNREFUSED’ undeclared (first use in this function)
         case WSAECONNREFUSED: return "Connection refused";
              ^
src/wsocket.c:391:14: error: ‘WSAEHOSTDOWN’ undeclared (first use in this function)
         case WSAEHOSTDOWN: return "Host is down";
              ^
src/wsocket.c:392:14: error: ‘WSAEHOSTUNREACH’ undeclared (first use in this function)
         case WSAEHOSTUNREACH: return "No route to host";
              ^
src/wsocket.c:393:14: error: ‘WSAEPROCLIM’ undeclared (first use in this function)
         case WSAEPROCLIM: return "Too many processes";
              ^
src/wsocket.c:394:14: error: ‘WSASYSNOTREADY’ undeclared (first use in this function)
         case WSASYSNOTREADY: return "Network subsystem is unavailable";
              ^
src/wsocket.c:395:14: error: ‘WSAVERNOTSUPPORTED’ undeclared (first use in this function)
         case WSAVERNOTSUPPORTED: return "Winsock.dll version out of range";
              ^
src/wsocket.c:396:14: error: ‘WSANOTINITIALISED’ undeclared (first use in this function)
         case WSANOTINITIALISED:
              ^
src/wsocket.c:398:14: error: ‘WSAEDISCON’ undeclared (first use in this function)
         case WSAEDISCON: return "Graceful shutdown in progress";
              ^
src/wsocket.c:399:14: error: ‘WSAHOST_NOT_FOUND’ undeclared (first use in this function)
         case WSAHOST_NOT_FOUND: return "Host not found";
              ^
src/wsocket.c:400:14: error: ‘WSATRY_AGAIN’ undeclared (first use in this function)
         case WSATRY_AGAIN: return "Nonauthoritative host not found";
              ^
src/wsocket.c:401:14: error: ‘WSANO_RECOVERY’ undeclared (first use in this function)
         case WSANO_RECOVERY: return "Nonrecoverable name lookup error";
              ^
src/wsocket.c:402:14: error: ‘WSANO_DATA’ undeclared (first use in this function)
         case WSANO_DATA: return "Valid name, no data record of requested type";
              ^
Error: failed to build LuaSocket

【问题讨论】:

  • 你不能只使用已经安装的副本,把它们放在游戏正在寻找它们的地方吗?
  • 我试过了,但是 a) 它请求我在安装中找不到的文件,并且 b) 我认为它们的版本不同(我相信我有一个旧版本的 Luasocket ) 或其他东西,因为当我在请求的地方添加 core.dll 时服务器崩溃。无论哪种方式,我都想编译 Luasocket 只是为了探索所有途径
  • 找不到哪些文件?你有什么版本? luasocket 本身的版本可能不如应用程序期望的 lua 版本(以及构建 luasocket 的 lua 版本)重要。
  • 应用程序需要 lua 5.2 的文件。我从 Github 获得了最新的(luasocket 3.0-rc1),但是我给它的文件是 2.0.2,即 Lua For Windows 附带的 LuaSocket 版本。我很乐意编译较新的,但试图给我上面的错误(并且使用旧的 core.dll 会使游戏崩溃)。所以,这是我的问题。 如何编译它? LuaRocks 也给了我一个错误。不幸的是,根据更新日志,这个版本的 LuaSocket 是添加了 Lua 5.2 兼容性的版本,该应用程序使用它,所以我必须使用它。提前致谢
  • 我可以看到这会导致问题。 LFW 附带的 LuaSocket 可能适用于 Lua 5.1。这意味着当您加载 core.dll 时,它也会尝试将 lua51.dll 拉入正在运行的进程中,这意味着您最终会将 lua52.dlllua51.dll 混合在一起。

标签: lua luasocket


【解决方案1】:

这个SO answer 可能会有所帮助。它提供了有关如何使用 gcc 进行编译的详细信息,以及对我使用的构建脚本的参考以及为 luasocket 3.0-rc1 和 Lua 5.2 编译的二进制文件。

【讨论】: