How to compile libraries for different Lua version?

A few days ago I had issues setting up a build environment for my router, which hnyman kindly helped me figure out.

Following his hint I modified the Makefiles for a few Lua libraries I need for my project:

  • package/system/ubus
  • feeds/packages/lang/lua-mosquitto
  • feeds/packages/lang/luv

I selected those packages in make menuconfig and changed the corresponding sections in their Makefiles like this:

define Package/libubus-lua
  SECTION:=libs
  CATEGORY:=Libraries
  DEPENDS:=+libubus +liblua5.3
  TITLE:=Lua binding for the OpenWrt RPC client
endef
define Package/lua-mosquitto                                                                                                                                                                   
    SUBMENU:=Lua                                                                                                                                                                               
    SECTION:=lang                                                                                                                                                                              
    CATEGORY:=Languages                                                                                                                                                                        
    TITLE:=Lua-mosquitto                                                                                                                                                                       
    DEPENDS:=+libmosquitto +lua5.3                                                                                                                                                             
    MAINTAINER:=Karl Palsson <karlp@etactica.com>                                                                                                                                              
endef
define Package/luv
  SUBMENU:=Lua
  SECTION:=lang
  CATEGORY:=Languages
  TITLE:=Luv
  URL:=https://github.com/luvit/luv
  DEPENDS:=+libuv +!LUV_USE_LUAJIT_ENGINE:lua5.3
endef

When running make all steps succeed and I can pull the *.so files from the resulting *.ipk files. But my router complains when I try to require the files from within Lua 5.3. This error tells me that the libraries got compiled against Lua5.1 so my changes did not have the wanted result.

error loading module 'luv' from file './luv.so':
	Error relocating ./luv.so: luaL_register: symbol not found

Did any of you compile libraries for Lua5.3 before and can tell me what I need to do? Any and all help is very much appreciated!

I made some slight progress by having luv compile and working.

However lua-mosquitto and libubus-lua still return a binary for Lua 5.1:

lua-mosquitto:

> require("mosquitto")
error loading module 'mosquitto' from file './mosquitto.so':
	Error relocating ./mosquitto.so: luaL_register: symbol not found
stack traceback:
	[C]: in ?
	[C]: in function 'require'
	stdin:1: in main chunk
	[C]: in ?

This is the part of the Makefile I changed:

define Package/lua-mosquitto
    SUBMENU:=Lua
    SECTION:=lang
    CATEGORY:=Languages
    TITLE:=Lua-mosquitto
    DEPENDS:=+libmosquitto +lua5.3 # +lua
    MAINTAINER:=Karl Palsson <karlp@etactica.com>
endef

Compilation output:

> make -j8 package/lua-mosquitto/compile
 make[1] package/lua-mosquitto/compile
 make[2] -C package/libs/toolchain compile
 make[2] -C feeds/packages/libs/c-ares compile
 make[2] -C feeds/packages/libs/cjson compile
 make[2] -C package/libs/openssl compile
 make[2] -C package/utils/lua5.3 compile
 make[2] -C feeds/packages/net/mosquitto compile
 make[2] -C feeds/packages/lang/lua-mosquitto compile

Same for ubus:

> require("ubus")
error loading module 'ubus' from file './ubus.so':
	Error relocating ./ubus.so: luaL_register: symbol not found
stack traceback:
	[C]: in ?
	[C]: in function 'require'
	stdin:1: in main chunk
	[C]: in ?

Makefile:

define Package/lua-mosquitto                                                                                                                                                                   
    SUBMENU:=Lua                                                                                                                                                                               
    SECTION:=lang                                                                                                                                                                              
    CATEGORY:=Languages                                                                                                                                                                        
    TITLE:=Lua-mosquitto                                                                                                                                                                       
    DEPENDS:=+libmosquitto +lua5.3 # +lua
    MAINTAINER:=Karl Palsson <karlp@etactica.com>                                                                                                                                              
endef

Compilation output:

> make -j8 package/ubus/compile
 make[1] package/ubus/compile
 make[2] -C package/libs/toolchain compile
 make[2] -C package/utils/lua compile           <= I think this is for libubox-lua which I do not need so irrelevant
 make[2] -C package/libs/libjson-c compile
 make[2] -C package/utils/lua5.3 compile
 make[2] -C package/libs/libubox compile
 make[2] -C package/system/ubus compile

I am thankful for any helping hand :slight_smile: