Skip to content

Undefined symbol error when using vendored Lua on Linux #524

@RanchMonster

Description

@RanchMonster

I am developing a cross-platform program for both Windows and Linux that embeds Lua to provide additional functionality.

On Windows, I build Lua as vendored (statically linked) to avoid the need for an external Lua DLL. This setup works without issues. However, when building on Linux with the same vendored Lua approach, I encounter the following runtime error when trying to load a Lua module:

failed to load module: runtime error: error loading module 'module' from file './lua/module/clibs/module.so': ./lua/module/clibs/module.so: undefined symbol: lua_pushlstring stack traceback: [C]: in ? [C]: in ? [C]: in function 'require' ./lua/module/init.lua:7: in main chunk [C]: in function 'require' [string "src/api.rs:858:17"]:4: in main chunk
It seems like the module's shared library (.so file) expects to link against a dynamically loaded Lua library, but since Lua is statically linked into my binary, the module cannot resolve lua_pushlstring and other Lua symbols.

Expected Behavior:

  • The program should work on Linux the same way it does on Windows when using a vendored (statically linked) Lua.
  • Lua modules should be able to load properly without missing symbol errors.

Steps to Reproduce:

  • Build the program on Linux with a statically linked (vendored) Lua.

  • Run the program and attempt to load a Lua module that includes a compiled .so file.

  • Observe the undefined symbol error when requiring the module.

  • Additional Information:

  • Lua is built vendored into the binary (no external Lua shared library).

  • The module being loaded is compiled separately and provides a .so file.

  • I would prefer to keep Lua statically linked rather than dynamically linking to a system-provided Lua shared library.

Possible Causes:

  • The .so module is expecting a dynamically linked Lua but isn't finding it because Lua is statically linked into my program.
  • Missing linker flags when building the Lua modules on Linux.

Questions:

  • Is there a recommended way to statically link Lua while ensuring external Lua modules can still work?
  • Should I be passing additional linker flags when compiling the Lua modules to ensure they link correctly against the statically linked Lua runtime?
  • Would I need to modify how the Lua modules are built to resolve this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions