linker error when root module doesn't have a main function
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
Please put an X between the brackets as you perform the following steps:
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - 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 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the fresh Lake project case: remove or rename the main function and run lake build. Trace the build and linking path responsible for the reported failure, then verify that the missing-main case produces the expected user-level error instead of a linker error.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100