Dynamic loading of libreadline opens wrong library filename

57 views
Skip to first unread message

Ross Burton

unread,
Mar 5, 2026, 9:29:30 AM (12 days ago) Mar 5
to lua-l
Hi,

As of lua 5.5[1] libreadline is no longer linked to at build time but instead dlopen()'d.  However, the library that is dlopen'd out of the box on Linux is "libreadline.so":

 #if defined(LUA_USE_LINUX)
 #define LUA_USE_POSIX
 #define LUA_USE_DLOPEN         /* needs an extra library: -ldl */
+#define LUA_READLINELIB                "libreadline.so"
 #endif

This filename will only be available on systems where readline was compiled by the user, where the readline development package has been installed.  For example, it will only be available on Debian systems where libreadline-dev has been installed[2], as the actual library is libreadline.so.8.2 (with a symlink of libreadline.so.8) [3].

Also, if readline changes API and switches to libreadline.so.9 then you might well be using the wrong API, causing crashes.

I think lua should be explicitly loading libreadline.so.8, this will work for everyone and be sure that you get a library with the ABI that you expect.

Cheers,
Ross

Yao Zi

unread,
Mar 5, 2026, 10:29:28 AM (12 days ago) Mar 5
to lu...@googlegroups.com
On Thu, Mar 05, 2026 at 06:14:25AM -0800, Ross Burton wrote:
> Hi,
>
> As of lua 5.5[1] libreadline is no longer linked to at build time but
> instead dlopen()'d. However, the library that is dlopen'd out of the box
> on Linux is "libreadline.so":
>
> #if defined(LUA_USE_LINUX)
> #define LUA_USE_POSIX
> #define LUA_USE_DLOPEN /* needs an extra library: -ldl */
> +#define LUA_READLINELIB "libreadline.so"
> #endif
>
> This filename will only be available on systems where readline was compiled
> by the user, where the readline development package has been installed.
> For example, it will only be available on Debian systems where
> libreadline-dev has been installed[2], as the actual library is
> libreadline.so.8.2 (with a symlink of libreadline.so.8) [3].
>
> Also, if readline changes API and switches to libreadline.so.9 then you
> might well be using the wrong API, causing crashes.
>
> I think lua should be explicitly loading libreadline.so.8, this will work
> for everyone and be sure that you get a library with the ABI that you
> expect.

Natanael has raised this before[4]. As a distro maintainer, I'll second
the idea, too.

> Cheers,
> Ross

Regards,
Yao Zi
[4]: https://groups.google.com/g/lua-l/c/yws8Wmgjcl0/m/LvTmtu2-DAAJ
Reply all
Reply to author
Forward
0 new messages