Repository navigation
extra-libraries: link on Linux - #31
Merged
Merged
Conversation
miso passes each library to mhs as -optl -lNAME, and mhs puts those flags before the runtime and the program's C file. GNU ld with --as-needed (the default on Ubuntu and Debian) drops a library that nothing before it needs, so a program using one failed with "undefined reference". On Linux, for native programs with extra-libraries, miso now passes -Wl,--no-as-needed before them. macOS's linker resolves libraries in any order (and does not take the flag); emcc (wasm-ld) does too. Checked with mhs and zlib on Ubuntu 24.04: with -optl -lz the link failed; with -optl -Wl,--no-as-needed first it linked and printed zlib's version. The smoke test now builds and runs a program with extra-libraries: [z] where the C compiler has zlib.
dmjio
force-pushed
the
extra-libraries-link-order
branch
from
October 23, 2026 02:12
f86d652 to
82befc9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug:
extra-libraries: [z]produced "undefined reference" on Linux. miso passes each library to mhs as-optl -lNAME, and mhs puts those flags before the runtime and the program's C file. GNU ld with--as-needed(the default on Ubuntu and Debian) drops a library that nothing before it needs.The fix: on Linux, for native programs with
extra-libraries, miso passes-Wl,--no-as-neededbefore them. macOS's linker and emcc (wasm-ld) resolve libraries in any order, so nothing changes there; macOS's linker doesn't accept the flag anyway.Checked with mhs and zlib on Ubuntu 24.04:
-optl -lz, the link failed;-optl -Wl,--no-as-neededfirst, it linked and printed zlib's version.New smoke test case: a program with
extra-libraries: [z]that prints zlib's version, wherever the C compiler has zlib.Note: this and #30 both add a case at the end of
scripts/smoke-test.sh. Whichever merges second will need a one-line conflict resolved.Generated by Claude Code