Bug 5573 – Compiler (not linker) should generate an error for missing main()

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-02-14T02:09:54Z
Last change time
2024-04-24T11:35:21Z
Keywords
bootcamp, pull
Assigned to
No Owner
Creator
Don

Comments

Comment #0 by clugdbug — 2011-02-14T02:09:54Z
The standard linker error is (a) newbie-hostile; and (b) on Windows, it generates an invalid executable. Running this executable seems to cause an infinite loop you cannot break out of. As Walter said on the newsgroup, it's not possible to solve this in general: > The problem is the main() can come from a library, or some other .obj > file handed to the compiler that the compiler doesn't look inside. It's > a very flexible way to build things, and trying to impose more order on > that will surely wind up with complaints from some developers. But, it's only the trivial case that matters. The compiler should generate an error if all files passed to the compiler are .d/.di files, and there is no use of pragma(lib). Error can be something like: "No main function, and no .obj or .lib file which could contain one".
Comment #1 by bearophile_hugs — 2011-02-14T04:04:23Z
See also bug 5215, bug 4680
Comment #2 by robert — 2011-02-14T13:03:52Z
Another possibility for this (and other linker errors) - given that dmd invokes the linker, its stderr could be redirected and filtered. The compiler can then give a nice error for a missing main() function, and also demangle symbol names without the linker needing modification. This avoids the issue of main() being in a library, but is also a bit more hacky.
Comment #3 by in — 2012-08-28T18:23:09Z
I agree that the emphasis should be on clarity of the error message rather than trying to out-think the programmer. The linker dump, to uninitiated noobs like me, looks an awful lot like a seg fault or bug with the compiler, not a flaw in the programmer.
Comment #4 by dlang-bot — 2024-01-11T22:39:13Z
@dkorpel created dlang/dmd pull request #16021 "Demangle symbols in linker errors" fixing this issue: - Demangle symbols in linker errors Fix issue 5573 https://github.com/dlang/dmd/pull/16021
Comment #5 by dlang-bot — 2024-04-24T11:35:21Z
dlang/dmd pull request #16021 "Demangle symbols in linker errors" was merged into master: - ac8d9556c2dbcdf553f648ab764cf36c0c3243ae by Dennis Korpel: Demangle symbols in linker errors Fix bugzilla issue 5573 https://github.com/dlang/dmd/pull/16021