Skip to content

Fix module mode linking on macOS#697

Open
ChrisJefferson wants to merge 1 commit into
mlua-rs:mainfrom
ChrisJefferson:fix-macos-module-linking
Open

Fix module mode linking on macOS#697
ChrisJefferson wants to merge 1 commit into
mlua-rs:mainfrom
ChrisJefferson:fix-macos-module-linking

Conversation

@ChrisJefferson

Copy link
Copy Markdown

When building a Lua C module (cdylib with the module feature) on macOS, the linker fails with undefined symbols for the Lua API. This is because macOS requires explicit -undefined dynamic_lookup to allow unresolved symbols in shared libraries — unlike Linux which permits them by default.

The build script already had platform-specific handling for Windows (raw-dylib linking). This adds the equivalent for macOS, passing the required linker flags so that Lua symbols are resolved at load time from the host interpreter.

Fixes the issue reported in #625 -- I didn't find that PR until after I fixed it because it's closed, do you mind putting it in the source?

@khvzak

khvzak commented Apr 30, 2026

Copy link
Copy Markdown
Member

I don't think this is going to work well. The build script should be in each module, not inside mlua-sys.
In particularly, if try to build a module with this change:

$ (cd tests/module && cargo build --release --features lua55)
warning: mlua-sys@0.11.0-rc.1: cargo:rustc-cdylib-link-arg was specified in the build script of mlua-sys v0.11.0-rc.1 (/Users/alex/Projects/mlua-rs/mlua/mlua-sys), but that package does not contain a cdylib target

Allowing this was an unintended change in the 1.50 release, and may become an error in the future. For more information, see <https://github.com/rust-lang/cargo/issues/9562>.

@ChrisJefferson ChrisJefferson force-pushed the fix-macos-module-linking branch from 389f27f to 033c72b Compare July 7, 2026 11:15
@ChrisJefferson

Copy link
Copy Markdown
Author

You are right, there is no need for changes here. I thought I needed changes in my repo and yours, and didn't carefully check this one was required. I totally misunderstood what was going on, sorry!

I've now more carefully understood what's happening and written a FAQ entry showing exactly how I fixed this in my project ( https://github.com/stacs-cp/demystify-rs ), and an example of what to put in their repo, in case that is helpful to other people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants