leanprover / leanprover/lean4

linker error when root module doesn't have a main function

Open
#4,752 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
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:

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
  1. make a fresh lake project
  2. delete or rename the main function
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.