leafo / lua-enet

Bindings to ENet for Lua
http://leafo.net/lua-enet/
85 stars 25 forks source link

lua-enet on Windows #1

Open sponge opened 13 years ago

sponge commented 13 years ago

I've been attempting to get the bindings building and running on Windows, and haven't had much luck. I was able to get a .dll generated but upon attempting to run the echo server example Lua outputs the following:

-- server.lua require "enet" local host = enet.host_create"localhost:6789" while true do local event = host:service(100) if event and event.type == "receive" then print("Got message: ", event.data, event.peer) event.peer:send(event.data) end end

lua: error loading module 'enet' from file '.\enet.dll': The specified procedure could not be found.

stack traceback:

    [C]: in function 'require'
    server\main.lua:2: in main chunk
    [C]: ?

I imagine I'm doing something stupid while building. Are there any binaries existing for Windows that are confirmed working? I wasn't able to get it working through luarocks (couldn't find ENET_DIR despite it being set correctly) and had to manually build it within VS2005.

leafo commented 13 years ago

I haven't personally built it on windows but I think someone else was successful. I have a working virtual machine now so I'll try to put together some binaries.

From that error it sounds like you built enet into its own dll but not lua-enet. Lua is looking for a specially named function in the dll that it can't find. Is that a possibility?

sponge commented 13 years ago

I really can't be sure. I did eventually get it working, although I honestly don't what specific steps that worked. I believe I built ENet using the provided Visual Studio project. I had to then modify the build commands that luarocks attempted to run to link to ws2_32 and winmm. I also had to modify an #ifdef WIN32 that for some reason wasn't being hit. It was attempting to include sys/time.h for the UNIX path. My working DLL was only a few hundred kb different in size than when I first posted the ticket.

Although I was able to get the basic echo server/client to work, my main goal is to use the lib in conjunction with www.love2d.org. Attempting to load the module in a Love gets me "An application has made an attempt to load the C runtime library incorrectly" when I require enet. I'm not quite sure if this is a problem with the way I built it, or a problem with the Love stuff, but it's a definite blocker for me on using lua-enet further.

I do believe I was able to get everything including loaded into Love2D on my Mac Mini, that was definitely straightforward compared to this.

leafo commented 13 years ago

Okay I built a windows verison using mingw. I tested it with the echo servers and was able to require it in love without any errors. Give it a shot and tell me if it works.

http://leafo.net/lua-enet/bin/

sponge commented 13 years ago

Fantastic, it seems to be working even within Love now. Was the build process under mingw significantly different from the "configure && make && make install" dance? Mainly if I need to dive into the wrapper source it would be nice to be able to generate a working binary myself.

(BTW, do you know someone named Tim Branyen? He and I are both RIT alum, and he recognized the name when I linked him to the project! Small world.)

leafo commented 13 years ago

It was pretty straight forward. I downloaded the enet source, then did sh configure then make to build libenet.a. I put the enet headers and the lib I just built into my mingw installation. Then I downloaded the LuaRocks windows binaries, and pulled out the lua headers and libs and dropped them into the mingw install.

Then from a checkout of lua-enet I ran:

gcc -O -shared -o enet.dll enet.c -lenet -llua51 -lws2_32 -lwinm

There is no dependency on luarocks, I just used it for the lua binaries. You could easily use the Lua Binaries package too.

I am actually trying to build love from scratch on windows. Now that is hard ;)

(Also yeah I know Tim. I am also an RIT alum.)

Ismoh commented 2 years ago

It's pretty old, but is there a luarocks fix? Still getting lua: error loading module 'enet' from file '.\enet.dll': The specified procedure could not be found. when using the dlls provided by @leafo. When trying to build it with luarocks I get this as well: couldn't find ENET_DIR

Any suggestions?

Ismoh commented 2 years ago

DONT DO THIS, it's unfortunately not working, because there might be a version missmatch to ENet!

If you stumble on this one, try the following:

Use one of the .dlls @leafo mention here

Okay I built a windows verison using mingw. I tested it with the echo servers and was able to require it in love without any errors. Give it a shot and tell me if it works.

http://leafo.net/lua-enet/bin/

For some reason 1.0-51 only worked for me.

And load the c package as follows:

local enet = nil
if enet == nil then
    print("Checking external enet c library 'enet.dll' loading..")
    enet = assert(package.loadlib(--[[ path_to_enet.dll ]], "luaopen_enet")) -- replace path_to_enet.dll
    enet()
    print("enet c library 'enet.dll' was loaded.")
end

https://www.lua.org/manual/5.1/manual.html#5.3 see package.loadlib (libname, funcname) package.loadlib(--[[ path_to_enet.dll ]], "*") -- asteriks isnt working in 5.1

Therefore use the standard function name to load c packages: luaopen_[libraryname]. You can find it here: https://github.com/leafo/lua-enet/blob/97d91e8c4337555425fa751f02f552bbb553f17b/enet.c#L775

Ismoh commented 2 years ago

9 days later, I found a solution to get the enet.dll running for my mod used in Noita. This is more or less specified to Noita, but may help someone in the future. There is a step-by-step description how I build it. Enjoy!