luasocket
luasocket copied to clipboard
unable to compile in 64bits for windows
I would like some help on the procedure to follow to compile this for a 5.1 64 bit lua on windows. I've been trying for a few days but programming isn't what I do for work and I've never compiled/worked with lua before and the whole thing is super confusing. Any help would be greatly appreciated!
(I've managed to compile it for linux when running ubuntu on windows but for windows i'm stuck)
what i've tried that seems to make the most sense so far is :
- editing win64.cmd to change lua version to 5.1
- editing vc64.bat to give it the proper path for vcvars64.bat
- editing the makefiles in luasocket-master/ and luasocket-master/src to change the build platform to win64
- starting win64.cmd (not if it does anything)
- starting vc64.bat (opens the mingw64 thing)
- cd to the luasocket-master/ folder
- make
this is the error I get :
Did I do anything wrong up to this point?
I've tried grabbing missing files from other places on my computer but they just reference other files util i get an error. And a lot of them have include
At this point it does things, albeit with a bunch of errors but then gets stuck here:
LINK : fatal error LNK1104: cannot open file 'C:\Program Files\Git\LIBPATH;C:\Program Files\Git\lib\lua\5.1\x64\Release.obj'
(I do not have this file anywhere on my computer)
Alternatively I've just tried to open it with visual studio again (community 2022) and it's just giving some errors instead of the many i had before that i had no idea how to fix:
How can i tell it to look for lua51.dll instead?
I'm not on Windows and haven't been for 25 years, but it seems like the bit you may be missing is specifying the base path to your Lua source header files. In fact several of the steps you took should have been unnecessary. Editing files in the luasocket source should not be needed, you just need a few ENV variables setup correctly so that it knows where your system stuff is (especially the Lua 5.1 sources) relative to the build location.
I would actually start from scratch and try using LuaRocks first. Do you have a working luarocks
in Windows? And can you luarocks install luasocket
? The advantage of this is that it knows a lot about where other Lua related stuff will be on your system and can likely wire up all the necessary environment variables.
If that works you can move on to perhaps downloading the source yourself and using luarocks build
. That should get you everything you need, but if you still need to use the manual make
method at least you'd be able to reference what environment variables were being used, such as where your Lua headers are.
I can do that yes but I beleive it's building 32 bit files and they don't work in the program i'm using which i believe is using 64bit. Also i edited the message above while you were sending this so check the last part.
Actually nvm since I assume you don't use VS from your message :p.
So using luarocks build gives the following.
So I guess I need to install lua in 64 bit somehow. I thought i did that but I guess not.
And fixing a bunch of other things as well.
Your are correct I don't use VS ;-)
And also correct, you will need a working Lua built with 64 bit support and matching header files somewhere before you can even approach building this library.
I forgot to say but thanks for the help. ;D could you clarify the thing about the header parts? I don't mind doing my own research but so i have directions on how to approach it.
The header files you need are part of the Lua sources. You need a built version of Lua of course, but in order to build other things like libraries that match with and can be loaded as modules into it, they must be able to reference the sources that match your Lua install. For example on Linux a Lua 5.1 installation might come with the binary in /usr/bin
and some shared libraries in /usr/lib
, but it will also include a number of *.h
files in /usr/include/lua5.1/
. Any time I build something for Lua5.1 there is usually an argument or environment variable that specifies where this folder is.
This project has some standard ones filled in already. It looks like if you run
make PLAT=win64 LUAV=5.1
...the src/makefile
will look here:
LUAINC_win64?=$(LUAPREFIX_win64)/include/lua/$(LUAV) $(LUAPREFIX_win64)/include/lua$(LUAV)
It looks like you may need to set LUAPREFIX_win64
yourself.
make PLAT=win64 LUAV=5.1 LUAPREFIX_win64="/c/base/path/to/include/dir"
It does look like I have a 64bit install of lua now as if i check the dll it makes with a tool called dependencywalker it indicated they are x64:
That being said i found this 32or64 function to test if it lua is using 32 or 64 and it indicated 32 if i run it.
https://stackoverflow.com/questions/48093429/determine-whether-lua-compiler-runs-32-or-64-bit
I'm not sure how trustworthy that function is but in the game I want to ultimated use sockets in it does say 64. And in that lua version i downloaded for which the dlls are 64 it says 32. So I'm a bit confused regarding that...
My the way the cmd32.cmd
and cmd64.cmd
files look like something an earlier maintainer hard coded to match their system and where they had sources. They don't look like generic things for others to use and should probably be removed / moved into documentation. But the latter of those is basically the command I've shown above, so I suspect you don't need to do any source editing at all, just get those paths right and call that command.
I'm not going to be much use for the 32 vs. 64 bit issue in Windows, but I assume once you have a working 64 bit Lua install this library should follow suit pretty easily.
Gotcha. In which folder should LUAPREFIX_win64 end?
wait actually if it goes in LUAPREFIX_win64)/include/lua/$(LUAV)
I don't have this folder structure : include\lua\5.1
edit ok i can't read mb!
alright so editing the makefile I think I got it working. It produced dlls, they are 64bit.
However when doing require ('socket') in the program I'm trying to use this with I now get:
Does that mean i compiled it incorrectly or would that relate to something else?
could that be because I renamed the output dll from socket-3.0.0.dll to socket.dll?
edit: probably not, I edited makefile to produce socket.dll instead and still getting the same error.
edit2: this might be the solution: https://stackoverflow.com/questions/55508395/lua-c-lib-windows-the-specified-procedure-could-not-be-found
does that mean my headers aren't set correctly in the makefile?
Edit: independently to my answer above i tried to add socket.lua and other files i've seen previously on precompiled luasockets for windows to my application folder.
This is what my application root folder looks like: |socket.lua |mime.lua |ltn12.lua |__socket | |core.dll (socket.dll renamed) |__mime | |core.dll (mime.dll renamed) edit2: I believe the game is using this version of lua https://github.com/openresty/luajit2 (see https://github.com/ac-custom-shaders-patch/acc-lua-sdk) so my current belief is that compiling for lua 5.1.5 x64 was not enough (despit the lua apps in game telling me the version is 5.1) and that i need to compile the dll for luajit2.
I think I somehow got stuff to work. Thanks a lot!
Somebody else contributed some Windows releated fixes that went into v3.1.0. I don't think it covered your specific set of issues, but it might be useful to revisit this and figure out what exactly if anything can be changed for the better here.
Hi guys,
i dont have Visual Studio and all the Dependencies to compile the project to get the DLL Binaries as well as i cannot have LuaRocks to install it. as i'm trying to create Lua script for OBS, and share it for others, and i guess the guys who will get it, will not be able to "install" lua dependencies
could you guys please share binaries, for Windows 64bit?
for copy and paste them into Lua scripts project directory to add custom ClassPath for require("socket.http") library in Lua script itself
thanks
@alerque I don't normally use 64-bit lua binaries and mingw but LuaSocket 3.1.0-1 appears to work fine for me. It compiled and I tried a quick listener/talker test.
- lua-5.4.2_Win64_bin
- luarocks-3.9.1-windows-64
-
winlibs-x86_64-posix-seh-gcc-12.1.0-llvm-14.0.6-mingw-w64ucrt-10.0.0-r3
(renamed
gcc.exe
tomingw32-gcc.exe
)
Thanks @Ketho that's great information.
Is there anything we should do with the packaging or documentation to facilitate this for Win64 folks? I think everything works but people also seem to bump into trouble on a regular basis, so I'm guessing they just don't know what to do.
I just realize I'm using WinLibs MinGW, and the original issue was more related to Visual Studio.
I actually don't really know much about tooling myself, just that I can do luarocks install luasocket
with the available lua binaries and a mingw distribution.
Better documentation for windows noobs like me would be great though but I suppose that's more a luarocks/windows problem.
I'm don't even have access to Windows to fiddle with, so any documentation improvements will have to be contributed by end users. I'm open to facilitating PRs if anybody wants to improve the docs we have for the benefit of future Windows users.