Tangent128 / luasdl2

A pure C binding of SDL 2.0 for Lua 5.1, Lua 5.2, and LuaJIT.
ISC License
385 stars 74 forks source link

Linux building luasdl2 complains none compatible version detected 5.4 #89

Closed Dragon20C closed 2 years ago

Dragon20C commented 2 years ago

I installed all the dependencies and lua 5.4 and I got the latest from the github page and it complains about lua 5.4 version being unsupported based on looking through the github page it seems to be compatible but when actually compiling/building it, it doesn't.

this is the message it errors out when running cmake ..

-- Found SDL2: /usr/lib/libSDL2.so found components: image mixer net ttf CMake Error at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find Lua: Found unsuitable version "5.4", but required is exact version "5.3" (found /usr/lib/liblua.so, ) Call Stack (most recent call first): /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:592 (_FPHSA_FAILURE_MESSAGE) cmake/FindLua.cmake:56 (find_package_handle_standard_args) CMakeLists.txt:53 (find_package)

-- Configuring incomplete, errors occurred! See also "/home/USERNAME/Downloads/luasdl2-master/build/CMakeFiles/CMakeOutput.log".

Tangent128 commented 2 years ago

Different systems like to put the lua headers and library in wildly different places, so you'll likely need to manually specify the paths.

An example command that works on my current Debian install looks like:

cmake .. -DWITH_LUAVER=5.4 -DLua_INCLUDE_DIR=/usr/include/lua5.4/ -DLua_LIBRARY=/usr/lib/x86_64-linux-gnu/liblua5.4.so

(Unfortunately the documentation in INSTALL.md is out of date and references Cmake variables that aren't used anymroe)

Dragon20C commented 2 years ago

@Tangent128 thank you very much, This is very useful I will try to configure it to my system.

Dragon20C commented 2 years ago

@Tangent128 okay so I think I configured it correctly, this is the command I used for my arch system :
cmake .. -DWITH_LUAVER=5.4 -DLua_INCLUDE_DIR=/usr/include/lua5.4/ -DLua_LIBRARY=/usr/lib/liblua5.4.so

on the (-DLua_INCLUDE_DIR=) I had to create a new folder for what ever reason when I installed lua it didnt create such a file and installed the lua files in just include folder.

then I did make and make install and it seemed to do something, next I open up visual studio and type the tutorial code

`local SDL = require "SDL"

local ret, err = SDL.init { SDL.flags.Video, SDL.flags.Audio }

if not ret then error(err) end`

and errors out saying this

lua: /mnt/1TB SSD/Lua Projects/SDL2-Lua/main.lua:1: module 'SDL' not found: no field package.preload['SDL'] no file '/usr/share/lua/5.4/SDL.lua' no file '/usr/share/lua/5.4/SDL/init.lua' no file '/usr/lib/lua/5.4/SDL.lua' no file '/usr/lib/lua/5.4/SDL/init.lua' no file './SDL.lua' no file './SDL/init.lua' no file '/usr/lib/lua/5.4/SDL.so' no file '/usr/lib/lua/5.4/loadall.so' no file './SDL.so'

I do have SDL installed, both sdl and sdl2, I assume the project failed somewhere by user error.

Tangent128 commented 2 years ago

(You solved it your own way, but fyi if your system's lua.h is found directly under /usr/include/, it should be sufficient to just -DLua_INCLUDE_DIR=/usr/include/)

Most likely the built SDL.so library did not end up on your system's Lua search path. Try copying SDL.so from your luasdl2 build folder into the folder containing your main.lua; if that works you can figure out which of those system-wide folders it best belongs in.

Dragon20C commented 2 years ago

@Tangent128 thank you very much, I have gotten it working now and I couldn't of done it without you, now I would suggest to update the install.MD or somehow make it easier for new comers to figure this out, I managed to understand how/where lua stores its files and figure the rest, maybe have a small bit for that command only and give some guess work on finding the correct locations. but my issue is resolved so I will close it.

Dragon20C commented 2 years ago

@Tangent128 sorry for bothering you again, so I am on tutorial 4 at the moment and I cant seem to get the image module to load at all, things I have tried is: Moving the image.io file that was in the build folder into the main.lua folder and it complains about not finding the module, I have also tried renaming it to SDL.image to see if that made any difference nope, error message down below.

lua: /mnt/1TB SSD/Lua Projects/SDL2-Lua/main.lua:2: module 'SDL.image' not found:
        no field package.preload['SDL.image']
        no file '/usr/share/lua/5.4/SDL/image.lua'
        no file '/usr/share/lua/5.4/SDL/image/init.lua'
        no file '/usr/lib/lua/5.4/SDL/image.lua'
        no file '/usr/lib/lua/5.4/SDL/image/init.lua'
        no file './SDL/image.lua'
        no file './SDL/image/init.lua'
        no file '/usr/lib/lua/5.4/SDL/image.so'
        no file '/usr/lib/lua/5.4/loadall.so'
        no file './SDL/image.so'
        no module 'SDL.image' in file './SDL.so
stack traceback:
        [C]: in function 'require'
        /mnt/1TB SSD/Lua Projects/SDL2-Lua/main.lua:2: in main chunk
        [C]: in ?
The terminal process "bash '-c', 'lua '/mnt/1TB SSD/Lua Projects/SDL2-Lua/main.lua''" failed to launch (exit code: 1).`

here is my code just in case it has something to do with it.


local SDL = require "SDL" 
local image = require "SDL.image"

local ret, err = SDL.init { -- Initilise SDL
    SDL.flags.Video,
    SDL.flags.Audio
}

if not ret then
error(err)
end

print()

print(string.format("SDL %d.%d.%d", --Prints SDL version installed in the system
    SDL.VERSION_MAJOR,
    SDL.VERSION_MINOR,
    SDL.VERSION_PATCH
))

local win, err = SDL.createWindow {
    title   = "Games!",      -- optional
    width   = 1280,                         -- optional
    height  = 720,                          -- optional
    flags   = { SDL.window.Resizable },     -- optional
    x       = (1080 / 2),        -- optional
    y       = (1920 / 2),        -- optional
    }

    if not win then
    error(err)
    end

local running = true
while running do
        --
        -- Iterate over all events, this function does not block.
        --
        for e in SDL.pollEvent() do
                if e.type == SDL.event.Quit then
                        running = false
                --elseif e.type == SDL.even then
                --elseif e.type == SDL.event.KeyDown then
                --        print(string.format("key down: %d -> %s", e.keysym.sym, SDL.getKeyName(e.keysym.sym)))
                --elseif e.type == SDL.event.MouseWheel then
                --        print(string.format("mouse wheel: %d, x=%d, y=%d", e.which, e.x, e.y))
                --elseif e.type == SDL.event.MouseButtonDown then
                --        print(string.format("mouse button down: %d, x=%d, y=%d", e.button, e.x, e.y))
                --elseif e.type == SDL.event.MouseMotion then
                --        print(string.format("mouse motion: x=%d, y=%d", e.x, e.y))
                end
        end
end

--SDL.delay(5000)
SDL.quit()
Dragon20C commented 2 years ago

I found a solution, so simply create this file/folder path "/usr/lib/lua/5.4/SDL/" and then put all the .so files into this folder and put SDL.so outside of the SDL folder so 5.4