`corelgilua51`

问题描述 投票:0回答:1

我正在尝试运行以下代码

local lgi = require("lgi")
local Gdk = lgi.Gdk
local Gtk = lgi.Gtk

Gtk.init()

-- Create a new window
local window = Gtk.Window({
    title = "LGI Test Window",
    default_width = 300,
    default_height = 200,
    on_destroy = Gtk.main_quit,
})

-- Create a label and add it to the window
local label = Gtk.Label({ label = "Hello, LGI!" })
window:add(label)
window:show_all()
Gtk.main()

但这给了我以下错误

lua: /home/username/.luarocks/share/lua/5.3/lgi/core.lua:14: module 'lgi.corelgilua51' not found:
    no field package.preload['lgi.corelgilua51']
    no file '/home/username/.luarocks/share/lua/5.3/lgi/corelgilua51.lua'
    no file '/home/username/.luarocks/share/lua/5.3/lgi/corelgilua51/init.lua'
    no file '/usr/local/share/lua/5.3/lgi/corelgilua51.lua'
    no file '/usr/local/share/lua/5.3/lgi/corelgilua51/init.lua'
    no file '/usr/local/lib/lua/5.3/lgi/corelgilua51.lua'
    no file '/usr/local/lib/lua/5.3/lgi/corelgilua51/init.lua'
    no file './lgi/corelgilua51.lua'
    no file './lgi/corelgilua51/init.lua'
    no file '/home/username/.luarocks/lib/lua/5.3/lgi/corelgilua51.so'
    no file '/usr/local/lib/lua/5.3/lgi/corelgilua51.so'
    no file '/usr/local/lib/lua/5.3/loadall.so'
    no file './lgi/corelgilua51.so'
    no file '/home/username/.luarocks/lib/lua/5.3/lgi.so'
    no file '/usr/local/lib/lua/5.3/lgi.so'
    no file '/usr/local/lib/lua/5.3/loadall.so'
    no file './lgi.so'
stack traceback:
    [C]: in function 'require'
    /home/username/.luarocks/share/lua/5.3/lgi/core.lua:14: in main chunk
    [C]: in function 'require'
    /home/username/.luarocks/share/lua/5.3/lgi/init.lua:19: in main chunk
    [C]: in function 'require'
    /home/username/.luarocks/share/lua/5.3/lgi.lua:19: in main chunk
    [C]: in function 'require'
    init2.lua:1: in main chunk

我已经设置了

LUA_PATH
LUA_CPATH
,但是从
lgi
安装
luarocks
没有
corelgilua51
,可能是什么问题,lgi只包含以下文件:-

drwxr-xr-x. 1 username username   226 Nov 15 13:01 .
drwxr-xr-x. 1 username username    30 Nov 15 13:05 ..
-rw-r--r--. 1 username username 15928 Nov 15 13:01 class.lua
-rw-r--r--. 1 username username 11130 Nov 15 13:01 component.lua
-rw-r--r--. 1 username username   761 Nov 15 13:01 core.lua
-rw-r--r--. 1 username username  3319 Nov 15 13:01 enum.lua
-rw-r--r--. 1 username username  5939 Nov 15 13:01 ffi.lua
-rw-r--r--. 1 username username  3403 Nov 15 13:01 init.lua
-rw-r--r--. 1 username username  1090 Nov 15 13:01 log.lua
-rw-r--r--. 1 username username  6217 Nov 15 13:01 namespace.lua
drwxr-xr-x. 1 username username   524 Nov 15 13:01 override
-rw-r--r--. 1 username username  1591 Nov 15 13:01 package.lua
-rw-r--r--. 1 username username  7088 Nov 15 13:01 record.lua
-rw-r--r--. 1 username username    15 Nov 15 13:01 version.lua

lua版本

5.3.6
,未升级到5.4,因为我尝试使用的项目需要低于5.4的lua版本,从
luarocks
安装时如何可以缺少模块,任何帮助将不胜感激。如果需要任何其他信息,请询问。

lua module gtk3 luarocks lgi
1个回答
0
投票

这个问题的原因是lgi的Makefile中的lib目录被硬编码为

/usr/local/lib/lua/5.1

PREFIX = /usr/local
LUA_VERSION=5.1
LUA_LIBDIR = $(PREFIX)/lib/lua/$(LUA_VERSION)
LUA_SHAREDIR = $(PREFIX)/share/lua/$(LUA_VERSION)
...
mkdir -p $(DESTDIR)$(LUA_LIBDIR)/lgi
cp $(CORE) $(DESTDIR)$(LUA_LIBDIR)/lgi

正如你在问题中看到的,当你在另一个版本的Lua中使用它时,它搜索的目录是

/usr/local/lib/lua/5.3/lgi.so
,这导致了错误。解决办法可以是修改Makefile中
LUA_VERSION
的值,或者将输出文件复制到正确的目录,或者更改
package.searchpath

© www.soinside.com 2019 - 2024. All rights reserved.