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

Linker Errors When Compiling LuaSystem on windows #15

Closed
Arethusag opened this issue Dec 17, 2023 · 8 comments · Fixed by #16
Closed

Linker Errors When Compiling LuaSystem on windows #15

Arethusag opened this issue Dec 17, 2023 · 8 comments · Fixed by #16

Comments

@Arethusag
Copy link

Arethusag commented Dec 17, 2023

Description

I am trying to install luasystem via luarocks on Windows, and the build is failing with the following error:

Error: Build error: Failed compiling module system/core.dll

Environment

Windows 10
Lua 5.1
LuaRocks 3.9.2 (64-bit)
GCC 13.2 from MSYS/MinGW-64 toolchain
shell: pwsh

Steps to reproduce

Run the following command in the above environment:
luarocks --lua-version=5.1 install luasystem

Full error message

Installing https://luarocks.org/luasystem-0.3.0-1.src.rock

gcc -O2 -c -o src/core.o -IC:\Program Files\lua\5.1\include src/core.c -DWINVER=0x0600 -D_WIN32_WINNT=0x0600 -Ic:/windows/system32/include -Ic:/windows/system32/include
gcc -O2 -c -o src/compat.o -IC:\Program Files\lua\5.1\include src/compat.c -DWINVER=0x0600 -D_WIN32_WINNT=0x0600 -Ic:/windows/system32/include -Ic:/windows/system32/include
gcc -O2 -c -o src/time.o -IC:\Program Files\lua\5.1\include src/time.c -DWINVER=0x0600 -D_WIN32_WINNT=0x0600 -Ic:/windows/system32/include -Ic:/windows/system32/include
gcc -O2 -c -o src/environment.o -IC:\Program Files\lua\5.1\include src/environment.c -DWINVER=0x0600 -D_WIN32_WINNT=0x0600 -Ic:/windows/system32/include -Ic:/windows/system32/include
gcc -O2 -c -o src/random.o -IC:\Program Files\lua\5.1\include src/random.c -DWINVER=0x0600 -D_WIN32_WINNT=0x0600 -Ic:/windows/system32/include -Ic:/windows/system32/include
gcc -O2 -c -o src/term.o -IC:\Program Files\lua\5.1\include src/term.c -DWINVER=0x0600 -D_WIN32_WINNT=0x0600 -Ic:/windows/system32/include -Ic:/windows/system32/include
gcc  -shared -o system/core.dll src/core.o src/compat.o src/time.o src/environment.o src/random.o src/term.o -Lc:/windows/system32 -Lc:/windows/system32 -ladvapi32 -lwinmm C:\Program Files\lua\5.1/bin/lua51.dll -lm
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/dllcrt2.o: in function `_CRT_INIT':
C:/M/B/src/mingw-w64/mingw-w64-crt/crt/crtdll.c:130:(.text+0x148): undefined reference to `_execute_onexit_table'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/dllcrt2.o: in function `pre_c_init':
C:/M/B/src/mingw-w64/mingw-w64-crt/crt/crtdll.c:64:(.text+0x8): undefined reference to `_initialize_onexit_table'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/dllcrt2.o: in function `atexit':
C:/M/B/src/mingw-w64/mingw-w64-crt/crt/crtdll.c:207:(.text+0x35b): undefined reference to `_register_onexit_function'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: src/term.o:term.c:(.text+0x1d): undefined reference to `fileno'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: src/term.o:term.c:(.text+0x24): undefined reference to `isatty'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/libmingw32.a(lib64_libmingw32_a-pseudo-reloc.o): in function `__report_error':
C:/M/B/src/mingw-w64/mingw-w64-crt/crt/pseudo-reloc.c:150:(.text+0x28): undefined reference to `__acrt_iob_func'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/M/B/src/mingw-w64/mingw-w64-crt/crt/pseudo-reloc.c:151:(.text+0x51): undefined reference to `__acrt_iob_func'
collect2.exe: error: ld returned 1 exit status

Error: Build error: Failed compiling module system/core.dll

Attempts to resolve:

  • Tried using 32-bit luarocks binaries and 32-bit MINGW env
  • The issue appears to be that there are undefined references to C runtime functions '_execute_onexit_table', '_initialize_onexit_table', and '_register_onexit_function'.
  • I have checked the win32 libraries "advapi32", "winmm" are in C:\WINDOWS\system32

Request for help

My first thought is that this is an issue in my windows environment, but I am not sure about how to proceed. Any advice on how to get this compiled via luarocks on windows?

@Tieske
Copy link
Member

Tieske commented Dec 19, 2023

here's a similar error; lunarmodules/luasocket#336

I just tested using the TDM releases for 32 and 64 bit, and they worked fine for me.

GCC version 10.3.0 (so that's old...)

@Tieske
Copy link
Member

Tieske commented Dec 19, 2023

also how did you compile Lua itself? Ensure to use the same toolchain for building Lua, installing LuaRocks, and executing LuaRocks.

@Tieske
Copy link
Member

Tieske commented Jan 2, 2024

ping @Arethusag

@Arethusag
Copy link
Author

Thanks @Tieske, I looked at #336, it does seem to be similar. Trying MSVC would be my next step.

I tried compiling luasystem again, this time on a new windows machine, and using the luarocks all-in-one package, and got the same error compiling with mingw

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/libmingw32.a(lib64_libmingw32_a-pseudo-reloc.o): in function `__report_error':
C:/M/B/src/mingw-w64/mingw-w64-crt/crt/pseudo-reloc.c:150:(.text+0x28): undefined reference to `__acrt_iob_func'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/M/B/src/mingw-w64/mingw-w64-crt/crt/pseudo-reloc.c:151:(.text+0x51): undefined reference to `__acrt_iob_func'
collect2.exe: error: ld returned 1 exit status 

My need to use luasystem is no longer, so I will not be testing this issue further.

@hishamhm
Copy link
Member

hishamhm commented Jan 5, 2024

I'm getting the same error in the Windows job of the Teal CI:

https://github.com/teal-language/tl/actions/runs/7375549890/job/20206856159?pr=730


C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/lib/../lib/dllcrt2.o:crtdll.c:(.text+0x148): undefined reference to `_execute_onexit_table'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.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/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/lib/../lib/dllcrt2.o:crtdll.c:(.text+0x34b): undefined reference to `_register_onexit_function'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: src/term.o:term.c:(.text+0x1d): undefined reference to `fileno'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: src/term.o:term.c:(.text+0x24): undefined reference to `isatty'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-pseudo-reloc.o):pseudo-reloc.c:(.text+0x28): undefined reference to `__acrt_iob_func'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-pseudo-reloc.o):pseudo-reloc.c:(.text+0x51): undefined reference to `__acrt_iob_func'
collect2.exe: error: ld returned 1 exit status

Error: Failed installing dependency: https://luarocks.org/busted-2.2.0-1.src.rock - Failed installing dependency: https://luarocks.org/luasystem-0.3.0-1.src.rock - Build error: Failed compiling module system/core.dll

This CI was working back in November with luasystem 0.2.1: https://github.com/teal-language/tl/actions/runs/6921415243/job/18826976992

hishamhm added a commit to teal-language/tl that referenced this issue Jan 5, 2024
hishamhm added a commit to teal-language/tl that referenced this issue Jan 5, 2024
hishamhm added a commit to teal-language/tl that referenced this issue Jan 5, 2024
@goldenstein64
Copy link
Contributor

goldenstein64 commented Jan 30, 2024

I tried applying changes in a similar way to fixing LuaSocket, lunarmodules/luasocket#321 (comment), and it seems to have worked, at least with MinGW.

diff --git a/luasystem-scm-0.rockspec b/luasystem-scm-0.rockspec
index 86209a6..ff5af61 100644
--- a/luasystem-scm-0.rockspec
+++ b/luasystem-scm-0.rockspec
@@ -42,6 +42,13 @@ local function make_platform(plat)
     win32 = { "advapi32", "winmm" },
     mingw32 = { },
   }
+  local libdirs = {
+    linux = nil,
+    unix = nil,
+    macosx = nil,
+    win32 = nil,
+    mingw32 = { },
+  }
   return {
     modules = {
       ['system.core'] = {
@@ -55,6 +62,7 @@ local function make_platform(plat)
         },
         defines = defines[plat],
         libraries = libraries[plat],
+        libdirs = libdirs[plat],
       },
     },
   }

I'll make a PR modifying the scm rockspec ahead of time.

@Tieske
Copy link
Member

Tieske commented Jan 30, 2024

@hishamhm I created a PR, alike your setup with Teal, to add the Windows platform to github actions, see #17. But the build fails with a Luarocks error: https://github.com/lunarmodules/luasystem/actions/runs/7716992556/job/21035164192?pr=17

tried older versions as well, but same thing everywhere. If we can verify the failure here, we can also test @goldenstein64 s fix for it.

Any hints to what might cause this?

@Tieske
Copy link
Member

Tieske commented Feb 14, 2024

PR was merged. I created a new rockspec, and CI pushed it to LuaRocks; https://luarocks.org/modules/lunarmodules/luasystem

So new rockspec 0.3.0-2 is up.

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

Successfully merging a pull request may close this issue.

4 participants