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

Linkage error on windows with mingw32 compiler (when compiling C source libraries) #1567

Open
RedNeath opened this issue Feb 16, 2024 · 5 comments
Labels

Comments

@RedNeath
Copy link

RedNeath commented Feb 16, 2024

  • Platform:

    • Windows
  • LuaRocks version:

    • 3.9.2
  • LuaRocks output from when the issue occurred:

mingw32-gcc -shared -o mime/core.dll src/mime.o src/compat.o C:\Program Files (x86)\Luarocks/lua5.1.lib -lMSCVCR80
  • Description:
    • This is the line that causes an error. The problem is with the include of the MSVCR80 lib, being a dll in windows. Instead of -lMSVCR80, it should be C:\Program Files (x86)\Luarocks/MSVCR80.dll. I tested it by changing the line extras[#extras+1] = "-l" .. (variables.MSVCRT or "m") to extras[#extras+1] = dir.path(variables.LUA_LIBDIR, (variables.MSVCRT or "m")) .. ".dll" in the builtin.lua script.
      Maybe this is not the most appropriate way to do it (especially the addition of ".dll" at the end), but it is just to give an example :)
@hishamhm
Copy link
Member

@RedNeath thanks for reporting. A few questions:

  1. did you install with install.bat or are you using luarocks.exe? I assume it was install.bat.
  2. what is the exact linkage error messages you are getting?
  3. What happens if you run luarocks config variables.MSVCRT m? Does it make compilation work?
  4. which flags did you use on install.bat? If possible, could you please run it again and paste the full output of execution here? It would be useful to know if you get any warnings.

I currently don't have a Windows machine to try these things myself, so help debugging Windows issues is greatly appreciated!

@RedNeath
Copy link
Author

No problem! :D

Just to point a few things out, because I'm not sure I have been explicit enough in my first comment: the abovementionned error doesn't come when installing luarocks, but when installing packages (or "rocks" I believe).
Also, note that solving this problem will not allow me to install any package anyway, because I installed Lua with the luarocks distribution (/L option), which installs a x86 version, and my c compiler is an arm compiler, as is the CPU of my device. I could compile and install lua on my own, but since my computer is not very powerful, and I am trying to create a RESTful API with pegasus.lua, I decided to use my IDE code transfer option to actually develop on a remote VPS.

  1. (& 4) I installed Luarocks using the install.bat script in an elevated powershell. Here is the full installation trace (including the command at the top).
C:\Users\Xiaomi\Downloads\luarocks-3.9.2-win32\luarocks-3.9.2-win32>.\install.bat /L 
LuaRocks 3.9.x installer.


========================
== Checking system... ==
========================


Admin privileges available for installing
Looking for Microsoft toolchain matching runtime MSVCR80 and architecture x86
    checking: HKLM\Software\Microsoft\VisualStudio\8.0\Setup\VC
    checking: HKLM\Software\Microsoft\VCExpress\8.0\Setup\VS
    Cannot auto-detect Windows SDK version from MSVCR80

==========================
== System check results ==
==========================

Will configure LuaRocks with the following paths:
LuaRocks        : C:\Program Files (x86)\LuaRocks
Config file     : C:\Program Files (x86)\LuaRocks\config-5.1.lua
Rocktree        : C:\Program Files (x86)\LuaRocks\systree

Lua interpreter : C:\Program Files (x86)\LuaRocks\lua5.1
    binaries    : C:\Program Files (x86)\LuaRocks
    libraries   : C:\Program Files (x86)\LuaRocks
    includes    : C:\Program Files (x86)\LuaRocks\include
    architecture: x86
    binary link : lua5.1.lib with runtime MSVCR80.dll

Compiler        : Microsoft (make sure it is in your path before using LuaRocks)

Press <ENTER> to start installing, or press <CTRL>+<C> to abort. Use install /? for installation options.

============================
== Installing LuaRocks... ==
============================


Installing LuaRocks in C:\Program Files (x86)\LuaRocks...
Installed the LuaRocks bundled Lua interpreter in C:\Program Files (x86)\LuaRocks
Created LuaRocks command: C:\Program Files (x86)\LuaRocks\luarocks.bat
Created LuaRocks command: C:\Program Files (x86)\LuaRocks\luarocks-admin.bat

Configuring LuaRocks...
Created LuaRocks hardcoded settings file: C:\Program Files (x86)\LuaRocks\lua\luarocks\core\hardcoded.lua
Created LuaRocks config file: C:\Program Files (x86)\LuaRocks\config-5.1.lua

Creating rocktrees...
Created system rocktree    : "C:\Program Files (x86)\LuaRocks\systree"
Local user rocktree exists : "C:\Users\Xiaomi\AppData\Roaming\LuaRocks"

Loading registry information for ".rockspec" files

============================
== LuaRocks is installed! ==
============================


You may want to add the following elements to your paths;
Lua interpreter;
  PATH     :   C:\Program Files (x86)\LuaRocks
  PATHEXT  :   .LUA
LuaRocks;
  PATH     :   C:\Program Files (x86)\LuaRocks
  LUA_PATH :   C:\Program Files (x86)\LuaRocks\lua\?.lua;C:\Program Files (x86)\LuaRocks\lua\?\init.lua
Local user rocktree (Note: %APPDATA% is user dependent);
  PATH     :   %APPDATA%\LuaRocks\bin
  LUA_PATH :   %APPDATA%\LuaRocks\share\lua\5.1\?.lua;%APPDATA%\LuaRocks\share\lua\5.1\?\init.lua
  LUA_CPATH:   %APPDATA%\LuaRocks\lib\lua\5.1\?.dll
System rocktree
  PATH     :   C:\Program Files (x86)\LuaRocks\systree\bin
  LUA_PATH :   C:\Program Files (x86)\LuaRocks\systree\share\lua\5.1\?.lua;C:\Program Files (x86)\LuaRocks\systree\share\lua\5.1\?\init.lua
  LUA_CPATH:   C:\Program Files (x86)\LuaRocks\systree\lib\lua\5.1\?.dll

Note that the %APPDATA% element in the paths above is user specific and it MUST be replaced by its actual value.
For the current user that value is: C:\Users\Xiaomi\AppData\Roaming.
  1. Here is the full output when trying to install the package pegasus (luarocks install pegasus)

NOTE:
Before running the command I set the environment variable CC to gcc, which is my c arm compiler (and the only one I have installed).

Installing https://luarocks.org/pegasus-1.0.3-0.src.rock
Missing dependencies for pegasus 1.0.3-0:
   luasocket >= 0.1.0-0 (not installed)
   luafilesystem >= 1.6 (not installed)
   lzlib >= 0.4.1.53-1 (not installed)

pegasus 1.0.3-0 depends on lua >= 5.1 (5.1-1 provided by VM)
pegasus 1.0.3-0 depends on mimetypes >= 1.0.0-1 (1.0.0-3 installed)
pegasus 1.0.3-0 depends on luasocket >= 0.1.0-0 (not installed)
Installing https://luarocks.org/luasocket-3.1.0-1.src.rock

luasocket 3.1.0-1 depends on lua >= 5.1 (5.1-1 provided by VM)
gcc -O2 -c -o src/mime.o -IC:\Program Files (x86)\LuaRocks\include src/mime.c -DLUASOCKET_DEBUG -DWINVER=0x0501
gcc -O2 -c -o src/compat.o -IC:\Program Files (x86)\LuaRocks\include src/compat.c -DLUASOCKET_DEBUG -DWINVER=0x0501
gcc  -shared -o mime/core.dll src/mime.o src/compat.o C:\Program Files (x86)\LuaRocks/lua5.1.lib -lMSVCR80
lld: error: unable to find library -lMSVCR80
gcc: error: linker command failed with exit code 1 (use -v to see invocation)

Error: Failed installing dependency: https://luarocks.org/luasocket-3.1.0-1.src.rock - Build error: Failed 
compiling module mime/core.dll

@Frityet
Copy link

Frityet commented Feb 23, 2024

No problem! :D

Just to point a few things out, because I'm not sure I have been explicit enough in my first comment: the abovementionned error doesn't come when installing luarocks, but when installing packages (or "rocks" I believe). Also, note that solving this problem will not allow me to install any package anyway, because I installed Lua with the luarocks distribution (/L option), which installs a x86 version, and my c compiler is an arm compiler, as is the CPU of my device. I could compile and install lua on my own, but since my computer is not very powerful, and I am trying to create a RESTful API with pegasus.lua, I decided to use my IDE code transfer option to actually develop on a remote VPS.

1. (& 4) I installed Luarocks using the `install.bat` script in an elevated powershell. Here is the full installation trace (including the command at the top).
C:\Users\Xiaomi\Downloads\luarocks-3.9.2-win32\luarocks-3.9.2-win32>.\install.bat /L 
LuaRocks 3.9.x installer.


========================
== Checking system... ==
========================


Admin privileges available for installing
Looking for Microsoft toolchain matching runtime MSVCR80 and architecture x86
    checking: HKLM\Software\Microsoft\VisualStudio\8.0\Setup\VC
    checking: HKLM\Software\Microsoft\VCExpress\8.0\Setup\VS
    Cannot auto-detect Windows SDK version from MSVCR80

==========================
== System check results ==
==========================

Will configure LuaRocks with the following paths:
LuaRocks        : C:\Program Files (x86)\LuaRocks
Config file     : C:\Program Files (x86)\LuaRocks\config-5.1.lua
Rocktree        : C:\Program Files (x86)\LuaRocks\systree

Lua interpreter : C:\Program Files (x86)\LuaRocks\lua5.1
    binaries    : C:\Program Files (x86)\LuaRocks
    libraries   : C:\Program Files (x86)\LuaRocks
    includes    : C:\Program Files (x86)\LuaRocks\include
    architecture: x86
    binary link : lua5.1.lib with runtime MSVCR80.dll

Compiler        : Microsoft (make sure it is in your path before using LuaRocks)

Press <ENTER> to start installing, or press <CTRL>+<C> to abort. Use install /? for installation options.

============================
== Installing LuaRocks... ==
============================


Installing LuaRocks in C:\Program Files (x86)\LuaRocks...
Installed the LuaRocks bundled Lua interpreter in C:\Program Files (x86)\LuaRocks
Created LuaRocks command: C:\Program Files (x86)\LuaRocks\luarocks.bat
Created LuaRocks command: C:\Program Files (x86)\LuaRocks\luarocks-admin.bat

Configuring LuaRocks...
Created LuaRocks hardcoded settings file: C:\Program Files (x86)\LuaRocks\lua\luarocks\core\hardcoded.lua
Created LuaRocks config file: C:\Program Files (x86)\LuaRocks\config-5.1.lua

Creating rocktrees...
Created system rocktree    : "C:\Program Files (x86)\LuaRocks\systree"
Local user rocktree exists : "C:\Users\Xiaomi\AppData\Roaming\LuaRocks"

Loading registry information for ".rockspec" files

============================
== LuaRocks is installed! ==
============================


You may want to add the following elements to your paths;
Lua interpreter;
  PATH     :   C:\Program Files (x86)\LuaRocks
  PATHEXT  :   .LUA
LuaRocks;
  PATH     :   C:\Program Files (x86)\LuaRocks
  LUA_PATH :   C:\Program Files (x86)\LuaRocks\lua\?.lua;C:\Program Files (x86)\LuaRocks\lua\?\init.lua
Local user rocktree (Note: %APPDATA% is user dependent);
  PATH     :   %APPDATA%\LuaRocks\bin
  LUA_PATH :   %APPDATA%\LuaRocks\share\lua\5.1\?.lua;%APPDATA%\LuaRocks\share\lua\5.1\?\init.lua
  LUA_CPATH:   %APPDATA%\LuaRocks\lib\lua\5.1\?.dll
System rocktree
  PATH     :   C:\Program Files (x86)\LuaRocks\systree\bin
  LUA_PATH :   C:\Program Files (x86)\LuaRocks\systree\share\lua\5.1\?.lua;C:\Program Files (x86)\LuaRocks\systree\share\lua\5.1\?\init.lua
  LUA_CPATH:   C:\Program Files (x86)\LuaRocks\systree\lib\lua\5.1\?.dll

Note that the %APPDATA% element in the paths above is user specific and it MUST be replaced by its actual value.
For the current user that value is: C:\Users\Xiaomi\AppData\Roaming.
2. Here is the full output when trying to install the package `pegasus` (`luarocks install pegasus`)

NOTE:
Before running the command I set the environment variable CC to gcc, which is my c arm compiler (and the only one I have installed).

Installing https://luarocks.org/pegasus-1.0.3-0.src.rock
Missing dependencies for pegasus 1.0.3-0:
   luasocket >= 0.1.0-0 (not installed)
   luafilesystem >= 1.6 (not installed)
   lzlib >= 0.4.1.53-1 (not installed)

pegasus 1.0.3-0 depends on lua >= 5.1 (5.1-1 provided by VM)
pegasus 1.0.3-0 depends on mimetypes >= 1.0.0-1 (1.0.0-3 installed)
pegasus 1.0.3-0 depends on luasocket >= 0.1.0-0 (not installed)
Installing https://luarocks.org/luasocket-3.1.0-1.src.rock

luasocket 3.1.0-1 depends on lua >= 5.1 (5.1-1 provided by VM)
gcc -O2 -c -o src/mime.o -IC:\Program Files (x86)\LuaRocks\include src/mime.c -DLUASOCKET_DEBUG -DWINVER=0x0501
gcc -O2 -c -o src/compat.o -IC:\Program Files (x86)\LuaRocks\include src/compat.c -DLUASOCKET_DEBUG -DWINVER=0x0501
gcc  -shared -o mime/core.dll src/mime.o src/compat.o C:\Program Files (x86)\LuaRocks/lua5.1.lib -lMSVCR80
lld: error: unable to find library -lMSVCR80
gcc: error: linker command failed with exit code 1 (use -v to see invocation)

Error: Failed installing dependency: https://luarocks.org/luasocket-3.1.0-1.src.rock - Build error: Failed 
compiling module mime/core.dll

Try compiling lua yourself, and in your luarocks config make it link with ucrt instead of msvcrt, I have had no issues after doing that

@RedNeath
Copy link
Author

Try compiling lua yourself, and in your luarocks config make it link with ucrt instead of msvcrt, I have had no issues after doing that

You're probably right. Sorry I didn't check that earlier but it seems I was wrong since the very beginning. From what I've seen, the mingw32 compiler actually uses the -L and -l options to link libraries, which means the command is probably correct.

I didn't take a look at how the installed compiler is detected (or if it even just is), but the one I use is the msys clang arm compiler (as shown by the trace below).

PS C:\Users\Xiaomi> where.exe gcc.exe
C:\msys64\clangarm64\bin\gcc.exe

PS C:\Users\Xiaomi> gcc --version
clang version 17.0.6
Target: aarch64-w64-windows-gnu
Thread model: posix
InstalledDir: C:/msys64/clangarm64/bin

I'll try to install Lua and Luarocks using this compiler someday and detail the installation procedure to make both run properly on an ARM 👍

@Frityet
Copy link

Frityet commented Feb 23, 2024

Try compiling lua yourself, and in your luarocks config make it link with ucrt instead of msvcrt, I have had no issues after doing that

You're probably right. Sorry I didn't check that earlier but it seems I was wrong since the very beginning. From what I've seen, the mingw32 compiler actually uses the -L and -l options to link libraries, which means the command is probably correct.

I didn't take a look at how the installed compiler is detected (or if it even just is), but the one I use is the msys clang arm compiler (as shown by the trace below).

PS C:\Users\Xiaomi> where.exe gcc.exe
C:\msys64\clangarm64\bin\gcc.exe

PS C:\Users\Xiaomi> gcc --version
clang version 17.0.6
Target: aarch64-w64-windows-gnu
Thread model: posix
InstalledDir: C:/msys64/clangarm64/bin

I'll try to install Lua and Luarocks using this compiler someday and detail the installation procedure to make both run properly on an ARM 👍

I created this tutorial which should also work on ARM, if you replace the parts where I delete the ARM bits with deleting the x86_64 bits

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

No branches or pull requests

3 participants