lean4
lean4 copied to clipboard
linker error when root module doesn't have a main function
Prerequisites
Please put an X between the brackets as you perform the following steps:
- [x] Check that your issue is not already filed: https://github.com/leanprover/lean4/issues
- [x] Reduce the issue to a minimal, self-contained, reproducible test case. Avoid dependencies to Mathlib or Batteries.
- [ ] Test your test case against the latest nightly release, for example on https://live.lean-lang.org/#project=lean-nightly (You can also use the settings there to switch to “Lean nightly”)
Description
If lake expects a module to be the root of an executable, but that module does not contain a main function in the root namespace, attempting to build results in a linker error rather than a more informative user-level error.
More broadly, I think all linker errors from lake build should be treated as bugs, and it would be good if lake build included a "This is likely a bug in Lake" type message whenever errors are emitted at the linking phase.
Context
Minimal discussion here: https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Linker.20error.20when.20no.20main
Steps to Reproduce
- make a fresh lake project
- delete or rename the main function
lake build
Expected behavior: A user-level error says that it expected to have a main function in module Main
Actual behavior: A massive linker error, such as
[dozens of lines omitted]
/nix/store/nd7ass1isid4vswpkfm82za4mcdwhzsm-binutils-2.41/bin/ld: Value.c:(.text+0xfb1c): undefined reference to `l_Lean_stringToMessageData'
/nix/store/nd7ass1isid4vswpkfm82za4mcdwhzsm-binutils-2.41/bin/ld: Value.c:(.text+0xfb57): undefined reference to `l_Lean_stringToMessageData'
/nix/store/nd7ass1isid4vswpkfm82za4mcdwhzsm-binutils-2.41/bin/ld: Value.c:(.text+0xfbdb): undefined reference to `l_Lean_stringToMessageData'
/nix/store/nd7ass1isid4vswpkfm82za4mcdwhzsm-binutils-2.41/bin/ld: Value.c:(.text+0xfd10): undefined reference to `l_Lean_stringToMessageData'
/nix/store/nd7ass1isid4vswpkfm82za4mcdwhzsm-binutils-2.41/bin/ld: Value.c:(.text+0xfd94): undefined reference to `l_Lean_stringToMessageData'
collect2: error: ld returned 1 exit status
error: external command '/home/james/.elan/toolchains/stable/bin/leanc' exited with code 1
Some builds logged failures:
- test
error: build failed
Versions
Lean 4.9.1, Elan from Nix NixOS unstable
Impact
Add :+1: to issues you consider important. If others are impacted by this issue, please ask them to add :+1: to it.