Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build x64 version via Luarocks on Windows or without it on Linux #316

Closed
avently opened this issue Aug 12, 2020 · 7 comments
Closed

Comments

@avently
Copy link

avently commented Aug 12, 2020

Hello. Actually I can't build x64 version of the library using all known ways. But since Luarocks should be the easiest solution I included it in the subject. So if you know any method I can use to build the x64 version of the lib, please, let me know (I can build x86 via Luarocks just fine).
So, what I did:

Output:

C:\Windows\system32>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.1-1 provided by VM)
x86_64-w64-mingw32-gcc -O2 -c -o src/mime.o -Ic:\lua5.1\include src/mime.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501
x86_64-w64-mingw32-gcc -O2 -c -o src/compat.o -Ic:\lua5.1\include src/compat.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501
x86_64-w64-mingw32-gcc -shared -o mime/core.dll src/mime.o src/compat.o c:\lua5.1\bin/lua5.1.dll -lm
x86_64-w64-mingw32-gcc -O2 -c -o src/luasocket.o -Ic:\lua5.1\include src/luasocket.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/timeout.o -Ic:\lua5.1\include src/timeout.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/buffer.o -Ic:\lua5.1\include src/buffer.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/io.o -Ic:\lua5.1\include src/io.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/auxiliar.o -Ic:\lua5.1\include src/auxiliar.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/options.o -Ic:\lua5.1\include src/options.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/inet.o -Ic:\lua5.1\include src/inet.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/except.o -Ic:\lua5.1\include src/except.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/select.o -Ic:\lua5.1\include src/select.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/tcp.o -Ic:\lua5.1\include src/tcp.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/udp.o -Ic:\lua5.1\include src/udp.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/compat.o -Ic:\lua5.1\include src/compat.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
x86_64-w64-mingw32-gcc -O2 -c -o src/wsocket.o -Ic:\lua5.1\include src/wsocket.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:/windows/system32/include
x86_64-w64-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 c:\lua5.1\bin/lua5.1.dll -lm
C:/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'
C:/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'
C:/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
C:/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'
C:/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

This is my config-5.1.lua:

rocks_trees = {
   {
      name = "user",
      root = "C:\\Users\\Me\\AppData\\Roaming/luarocks"
   },
   {
      name = "system",
      root = "c:\\lua5.1\\"
   }
}
variables = {
   CC = "x86_64-w64-mingw32-gcc",
   LD = "x86_64-w64-mingw32-gcc",
   LUALIB = "lua5.1.lib",
   MAKE = "x86_64-w64-mingw32-make",
}
verbose = false

How do you build Luasocket with x64 arch?

@kou
Copy link

kou commented Aug 13, 2020

It seems that https://sourceforge.net/projects/luabinaries/files/5.1.5/Tools%20Executables/ is built with Visual C++.
You need to use Visual C++ not MinGW to build LuaSocket for the Lua.

@avently
Copy link
Author

avently commented Aug 13, 2020

@kou, thank you, I tried it. There were no errors but no final binary too. I used cygwin with exported environment variables from Visual C++.
For now I figured out how to build on Arch. Will be useful for someone:
x64

make clean LUAV=5.3 PLAT=mingw LUAINC_mingw_base=/usr/x86_64-w64-mingw32/include LUAINC_mingw=/usr/x86_64-w64-mingw32/include LUALIB_mingw_base=/usr/x86_64-w64-mingw32/bin LUALIB_mingw=/usr/x86_64-w64-mingw32/bin/lua53.dll LUAPREFIX_mingw=/tmp CDIR_mingw=lua/5.3 LDIR_mingw=lua/5.3/lua install-both

x86

make clean LUAV=5.1 PLAT=mingw LUAINC_mingw_base=/usr/i686-w64-mingw32/include LUAINC_mingw=/usr/i686-w64-mingw32/include/lua5.1 LUALIB_mingw_base=/usr/i686-w64-mingw32/bin LUALIB_mingw=/usr/i686-w64-mingw32/bin/lua51.dll LUAPREFIX_mingw=/tmp CDIR_mingw=lua/5.1 LDIR_mingw=lua/5.1/lua install-both

After two days of googling and building I can rest:) Glad that Arch exists. Anyway, thank you for your answer! And your PR #312 helped me to build x86 with Lua 5.1. WIthout the PR I got an error.

@kou
Copy link

kou commented Aug 13, 2020

Why did you use Cygwin to use Visual C++?
You should use "command prompt for Visual C++" and luarocks.exe --lua-dir %LUA_DIR% install luasocket: https://github.com/diegonehab/luasocket/pull/315/files#diff-222da3d5159ccbea64c56d21b445f986R85-R86

@kou
Copy link

kou commented Aug 13, 2020

FYI: Here are my try to build 64bit binary on Debian GNU/Linux:

wget https://www.lua.org/ftp/lua-5.1.5.tar.gz
tar xf lua-5.1.5.tar.gz
cd lua-5.1.5
make INSTALL_TOP=/tmp/lua.mingw64 CC=x86_64-w64-mingw32-gcc TO_BIN="lua.exe luac.exe lua51.dll" mingw install
cd -
git clone https://github.com/diegonehab/luasocket.git
cd luasocket/src
make \
  prefix=/tmp/lua.mingw64 \
  LDIR_mingw=bin/lua \
  CDIR_mingw=bin \
  LUAINC_mingw=/tmp/lua.mingw64/include \
  LUALIB_mingw=/tmp/lua.mingw64/bin/lua51.dll \
  CC_mingw=x86_64-w64-mingw32-gcc \
  LD_mingw=x86_64-w64-mingw32-gcc \
  PLAT=mingw \
  all install
cd -
/tmp/lua.mingw64/bin/lua.exe -e 'print(require("socket"))'
# -> table: 0000000000423EF0

@avently
Copy link
Author

avently commented Aug 13, 2020

Why did you use Cygwin to use Visual C++?

It was one of my tries when other methods didn't work. I literally lost more time on building luasocket then on making my lua lib with 300 lines of code:)

FYI: Here are my try to build 64bit binary on Debian GNU/Linux:.....

This is the best answer ever! I'm curious why such things are not in readme? Top level readme file is actually useless right now but this info could be really helpfull for every visitor

@kou
Copy link

kou commented Aug 13, 2020

Can we close this?

@avently avently closed this as completed Aug 13, 2020
@Abrosimov-a-a
Copy link

Abrosimov-a-a commented Dec 7, 2021

@avently This is luarocks configuration error.

external_deps_dirs = {
    'c:\\my\\mingw64',
    'c:\\my\\mingw64\\x86_64-w64-mingw32',
    'c:\\Windows\\System32'
}

In mingw64 and mingw64\x86_64-w64-mingw32 should be bin, lib, include dirs.
c:\Windows\System32 should be the last.
usr must be the first for msys2.

Set mingw to make:

luarocks config variables.PLAT 'mingw'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants