leanprover / leanprover/lean4

Unnecessarily verbose error message when main is undefined

Open
#12,378 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P-low
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

If the main function has been renamed or is otherwise not present in a Lean executable, lake build gives an error message referencing the linker and C compiler. I would expect it to instead tell the user that they need a main function. Right now it looks almost like Lean has a bug or that there is a problem with the C compiler's setup.

Steps to reproduce (I am on Linux Mint):

lake new myproject
cd myproject

Now, rename main to something else in Main.lean. Then run:

lake build

This will give an error message like:

info: myproject: no previous manifest, creating one from scratch
info: toolchain not updated; already up-to-date
✖ [8/8] Building myproject:exe
trace: .> /home/niels/.elan/toolchains/leanprover--lean4---v4.27.0/bin/clang -o /home/niels/Documents/Scratch/myproject/.lake/build/bin/myproject /home/niels/Documents/Scratch/myproject/.lake/build/ir/Main.c.o.export /home/niels/Documents/Scratch/myproject/.lake/build/ir/Myproject/Basic.c.o.export /home/niels/Documents/Scratch/myproject/.lake/build/ir/Myproject.c.o.export -L /home/niels/.elan/toolchains/leanprover--lean4---v4.27.0/lib/lean --sysroot /home/niels/.elan/toolchains/leanprover--lean4---v4.27.0 -L /home/niels/.elan/toolchains/leanprover--lean4---v4.27.0/lib -L /home/niels/.elan/toolchains/leanprover--lean4---v4.27.0/lib/glibc -lc -lc_nonshared -Wl,--as-needed -l:ld.so -Wl,--no-as-needed -lpthread_nonshared -Wl,--as-needed -Wl,-Bstatic -lgmp -lunwind -luv -Wl,-Bdynamic -Wl,--no-as-needed -fuse-ld=lld -Wl,--start-group -lleancpp -lLean -Wl,--end-group -lStd -Wl,--start-group -lInit -lleanrt -Wl,--end-group -Wl,-Bstatic -lc++ -lc++abi -Wl,-Bdynamic -lLake -Wl,--as-needed -lgmp -luv -lpthread -ldl -lrt -Wl,--no-as-needed -lm -ldl -pthread
info: stderr:
ld.lld: error: undefined symbol: main
>>> referenced by start.S:104 (../sysdeps/x86_64/start.S:104)
>>>               /home/niels/.elan/toolchains/leanprover--lean4---v4.27.0/lib/Scrt1.o:(_start)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: external command '/home/niels/.elan/toolchains/leanprover--lean4---v4.27.0/bin/clang' exited with code 1
Some required targets logged failures:
- myproject:exe
error: build failed

I would rather it gave a message like:

error: build failed. Did not find a `main` function in the executable "myproject"

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

Reproduce the issue with a new project by renaming main in Main.lean and running lake build. Start from the executable build failure and make the missing-entry-point case report that no main function was found in the executable instead of exposing the linker and C compiler error; verify the revised message with the reproduction steps.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux
Domain
build-system, compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.