Compiling Lua with dynamic library support

57 views
Skip to first unread message

Stefano Cossu

unread,
Nov 20, 2025, 12:01:56 PM (7 days ago) Nov 20
to lu...@googlegroups.com
Hello,

I am debugging a segfault in a C extension for Lua and I need to print
out the stack trace to find which Lua line caused the segfault.

In order to see meaningful info in the stack, I compiled Lua from source
activating debug symbols (Lua 5.4.8 on Linux x64):

make linux CFLAGS=-ggdb
sudo make install INSTALL_TOP=/opt/lua-5.4-dbg
sudo ln -s /opt/lua-5.4-dbg/bin/lua /usr/local/bin/lua-dbg

But when I try to import a C module from the debug version, I get an error:

lua-dbg -e 'require "lfs"'
lua-dbg: error loading module 'lfs' from file
'/home/ste/.luarocks/lib/lua/5.4/lfs.so':
dynamic libraries not enabled; check your Lua installation
stack traceback:
[C]: in ?
[C]: in function 'require'
(command line):1: in main chunk
[C]: in ?

Which compile option(s) am I misssing?

Thanks
s
OpenPGP_0x1716A1B35E826596.asc
OpenPGP_signature.asc

Gé Weijers

unread,
Nov 20, 2025, 12:48:16 PM (7 days ago) Nov 20
to lu...@googlegroups.com
Hi,

I suspect that overriding CFLAGS on the command line is not a good idea, it overrides the -DLUA_USE_LINUX compiler option, which implies the use of libdl, the dynamic linker interface. I would edit the Makefile in the 'src' directory, and replace -O2 with your -ggdb option temporarily.

Hope this helps.



--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lua-l+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/lua-l/9fed7f44-df62-4a7c-b12e-5cd5f5eeb7d8%40cossu.cc.


--

Scott Morgan

unread,
Nov 20, 2025, 1:01:57 PM (7 days ago) Nov 20
to lu...@googlegroups.com
On 20/11/2025 17:01, 'Stefano Cossu' via lua-l wrote:
> Hello,
>
> I am debugging a segfault in a C extension for Lua and I need to print
> out the stack trace to find which Lua line caused the segfault.
>
> In order to see meaningful info in the stack, I compiled Lua from source
> activating debug symbols (Lua 5.4.8 on Linux x64):
>
> make linux CFLAGS=-ggdb

Shouldn't that be:

MYCFLAGS=-ggdb make linux

The Lua Makefile (the main one in src/) uses the $(MYCFLAGS) env var to
add options to the build, and the var needs to be set before the make
command rather than after it.

Scott

Luiz Henrique de Figueiredo

unread,
Nov 20, 2025, 1:06:10 PM (7 days ago) Nov 20
to lu...@googlegroups.com
> Shouldn't that be:
> MYCFLAGS=-ggdb make linux

make linux MYCFLAGS=-ggdb should work just fine both in top-level Lua
dir and in src/

Stefano

unread,
Nov 20, 2025, 5:46:14 PM (7 days ago) Nov 20
to lua-l
MYCFLAGS=-ggdb make linux

does not add the flag but 

make linux MYCFLAGS=-ggdb

does while leaving -DLUA_USE_LINUX in place.

Thanks!
s

Reply all
Reply to author
Forward
0 new messages