What does it mean when Makefile install succeeds and LuaRocks 3.3.1 install fails
Hello, I'm trying to install via LuaRocks 3.3.1 and received Error: Build error: Failed compiling module socket/core.dll
The install log is at https://gist.github.com/ergodicbreak/ec929794cebe830e09d0de73a1346124
My environment:
C:\Users\george>where gcc
C:\Users\george\bin\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\gcc.exe
C:\Users\george>where lua
C:\Users\george\bin\Lua\Lua-5.3.5\bin\lua.exe
C:\Users\george>echo %LUA_PATH_5_3%
C:\Users\george\AppData\Roaming\LuaRocks\share\lua\5.3\?.lua;C:\Users\george\AppData\Roaming\LuaRocks\share\lua\5.3\?\init.lua
C:\Users\george>echo %LUA_CPATH_5_3%
C:\Users\george\AppData\Roaming\LuaRocks\lib\lua\5.3\?.dll
C:\Users\george>luarocks --version
C:\Users\george\bin\LuaRocks\luarocks.lua 3.3.1
LuaRocks main command-line interface
For reference my LuaRocks config is at https://gist.github.com/ergodicbreak/1124a2bf4be858db4f75c6a79a0a4a2c
Thanks for any help or pointers, searching hasn't turned up much so far.
I've made some progress on this and I would welcome any feedback. After no success installing via Luarocks as in the OP, I customized the makefile to use my existing mingw-64 toolchain and Lua install, ending up with this:
changes to makefile
# PLAT: linux macosx win32 win64 mingw custom
# platform to build for
PLAT?=custom
# LUAV: 5.1 5.2
# lua version to build against
LUAV?=5.3
# where lua headers are found for custom builds
# LUAINC_custom:
# C:\Users\george\bin\Lua\Lua-5.3.5
LUAINC_custom_base?=C:\Users\george\bin\Lua\Lua-5.3.5
LUAINC_custom?=$(LUAINC_custom_base)/include
LUALIB_custom_base?=C:\Users\george\bin\Lua\Lua-5.3.5/lib
LUALIB_custom?=$(LUALIB_custom_base)/lua$(subst .,,$(LUAV)).dll
LUAPREFIX_custom?=c:/users/george/.luarocks
CDIR_custom?=lib/lua/5.3
LDIR_custom?=share/lua/5.3
#------
# Compiler and linker settings
# for custom
SO_custom=dll
O_custom=o
CC_custom=gcc
DEF_custom= -DLUASOCKET_$(DEBUG) \
-DWINVER=0x0501
CFLAGS_custom=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common
LDFLAGS_custom= $(LUALIB) -shared -Wl,-s -lws2_32 -o
LD_custom=gcc
SOCKET_custom=wsocket.o
Mostly copying the existing mingw settings. With these changes I was able to make custom && make install successfully.
C:\Users\george\Downloads\luasocket>mingw32-make test lua test/hello.lua Hello from LuaSocket 3.0-rc1 and MIME 1.0.3!
C:\Users\george\Downloads\luasocket>lua Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio
socket = require("socket")
At this point I'm trying to figure out what Luarocks is doing differently.
Thank you for pursuing this! Looking forward to further details.
So I've now successfully installed Luasocket with LuaRocks, but I don't understand why it worked, so maybe someone can enlighten me.
I took the brute force approach of making the LuaRocks command output identical to the Makefile output. For example, here is a comparison of a part of the output after I had already made some changes to LuaRocks.
LuaRocks:
gcc -O2 -c -o src/udp.o -IC:\Users\george\bin\Lua\Lua-5.3.5\include src/udp.c -DLUASOCKET_NODEBUG -DWINVER=0x0501 -Ic:/windows/system32/include
gcc -shared -o socket/core.dll src/luasocket.o src/timeout.o src/buffer.o src/io.o src/auxiliar.o src/compat.o src/options.o src/inet.o src/wsocket.o src/except.o src/select.o src/tcp.o src/udp.o -Lc:/windows/system32 -lws2_32 C:\Users\george\bin\Lua\Lua-5.3.5\lib/lua53.dll -lm
Makefile
gcc -IC:\Users\george\bin\Lua\Lua-5.3.5/include -DLUASOCKET_NODEBUG -DWINVER=0x0501 -Wall -O2 -fno-common -c -o udp.o udp.c
gcc luasocket.o timeout.o buffer.o io.o auxiliar.o compat.o options.o inet.o wsocket.o except.o select.o tcp.o udp.o C:\Users\george\bin\Lua\Lua-5.3.5/lib/lua53.dll -shared -Wl,-s -lws2_32 -o socket-3.0-rc1.dll
At this point LuaRocks was still explicitly including c:/windows/system32 and the makefile was not, so I removed that path from Luarocks by hacking it out of LuaRocks\lua\luarocks\build\builtin.lua. I would have preferred to do this in my Luarocks config but AfAICT that isn't possible.
For whatever reason, I then got a successful install. This is LuaRocks seeing my original successful makefile install:
Warning: c:/users/george/.luarocks/lib/lua/5.3/socket/core.dll is not tracked by this installation of LuaRocks. Moving it to c:/users/george/.luarocks/lib/lua/5.3/socket/core.dll~ Warning: c:/users/george/.luarocks/lib/lua/5.3/mime/core.dll is not tracked by this installation of LuaRocks. Moving it to c:/users/george/.luarocks/lib/lua/5.3/mime/core.dll~ luasocket 3.0rc2-1 is now installed in c:/users/george/.luarocks (license: MIT)
I don't know why the system32 include made a difference. That the makefile doesn't explicitly include that path doesn't seem to matter, for example I analyzed the dll produced by the makefile:
Imports: KERNEL32.dll msvcrt.dll WS2_32.dll lua53.dll Done analyzing: 'src/socket-3.0-rc1.dll'
And it still links with the dlls in system32.
The same analysis on the LuaRocks produced dll:
Imports: KERNEL32.dll msvcrt.dll WS2_32.dll lua53.dll Done analyzing: 'C:\Users\george.luarocks\lib\lua\5.3\socket\core.dll'
(this is done with the pe-parser module).
So at this point I have a solution but it doesn't seem like a good one. I'm going to see what the LuaRocks folks have to say about it.
I should point out that to use LuaRocks to fetch/build the latest LuaSocket git master, you should use:
luarocks install luasocket --server https://luarocks.org/dev
I'd be curious if this behaves differently for you.
Thanks that's worth looking into. Though after my first try with LuaRocks didn't succeed, I cloned luasocket master and worked off of that (with luarocks make), so I could modify the rockspec. So I think I've already tested that?
Yes, that's basically the same thing. Thanks!
I should point out that to use LuaRocks to fetch/build the latest LuaSocket git master, you should use:
luarocks install luasocket --server https://luarocks.org/devI'd be curious if this behaves differently for you.
Same problem:
PS C:\Users\*******> luarocks install luasocket --server https://luarocks.org/dev
Installing https://luarocks.org/dev/luasocket-scm-2.src.rock
luasocket scm-2 depends on lua >= 5.1 (5.2-1 provided by VM)
mingw32-gcc -O2 -c -o src/luasocket.o -ID:\software\Lua\5.2.4\include src/luasocket.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
mingw32-gcc -O2 -c -o src/timeout.o -ID:\software\Lua\5.2.4\include src/timeout.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
mingw32-gcc -O2 -c -o src/buffer.o -ID:\software\Lua\5.2.4\include src/buffer.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
mingw32-gcc -O2 -c -o src/io.o -ID:\software\Lua\5.2.4\include src/io.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
mingw32-gcc -O2 -c -o src/auxiliar.o -ID:\software\Lua\5.2.4\include src/auxiliar.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
mingw32-gcc -O2 -c -o src/options.o -ID:\software\Lua\5.2.4\include src/options.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
mingw32-gcc -O2 -c -o src/inet.o -ID:\software\Lua\5.2.4\include src/inet.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
mingw32-gcc -O2 -c -o src/except.o -ID:\software\Lua\5.2.4\include src/except.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
mingw32-gcc -O2 -c -o src/select.o -ID:\software\Lua\5.2.4\include src/select.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
mingw32-gcc -O2 -c -o src/tcp.o -ID:\software\Lua\5.2.4\include src/tcp.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
mingw32-gcc -O2 -c -o src/udp.o -ID:\software\Lua\5.2.4\include src/udp.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
mingw32-gcc -O2 -c -o src/compat.o -ID:\software\Lua\5.2.4\include src/compat.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
mingw32-gcc -O2 -c -o src/wsocket.o -ID:\software\Lua\5.2.4\include src/wsocket.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
mingw32-gcc -shared -o socket/core.dll src/luasocket.o src/timeout.o src/buffer.o src/io.o src/auxiliar.o src/options.o src/inet.o src/except.o src/select.o src/tcp.o src/udp.o src/compat.o src/wsocket.o -Lc:/windows/system32 -lws2_32 D:\software\Lua\5.2.4/lua52.dll -lMSVCRT
D:/software/Mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/dllcrt2.o:crtdll.c:(.text+0x16d): undefined reference to `_execute_onexit_table'
D:/software/Mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/dllcrt2.o:crtdll.c:(.text+0x8): undefined reference to `_initialize_onexit_table'
D:/software/Mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/dllcrt2.o:crtdll.c:(.text+0x38b): undefined reference to `_register_onexit_function'
src/inet.o:inet.c:(.text+0x7cd): undefined reference to `gai_strerrorA'
src/inet.o:inet.c:(.text+0x98d): undefined reference to `gai_strerrorA'
src/udp.o:udp.c:(.text+0x6d3): undefined reference to `gai_strerrorA'
src/udp.o:udp.c:(.text+0xaa6): undefined reference to `gai_strerrorA'
src/udp.o:udp.c:(.text+0xb18): undefined reference to `gai_strerrorA'
src/wsocket.o:wsocket.c:(.text+0xec6): more undefined references to `gai_strerrorA' follow
D:/software/Mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-pseudo-reloc.o):pseudo-reloc.c:(.text.unlikely+0x28): undefined reference to `__acrt_iob_func'
D:/software/Mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-pseudo-reloc.o):pseudo-reloc.c:(.text.unlikely+0x51): undefined reference to `__acrt_iob_func'
collect2.exe: error: ld returned 1 exit status
Error: Build error: Failed compiling module socket/core.dll