Currently if gcj is asked to link a program with no --main specified, it will blindly proceed, thus guaranteeing a moderatwly obscure linker error message in response to a simple compilation attempt like
Since most naive users are likely to try invoking it this way first, it would be really nice if it were a bit friendlier.
Based on a brief discussion on the Java mailing list, there seems to be some tentative agreement that:
If the only file arguments are .java and .class files, and there is no --main:
1) If there is exactly one file argument, generate the --main
2) If there is more than one, issue a warning, suggesting --main. (This gets a little tricky if there are nonstandard libraries involved, which might be hiding main. If none are explicitly listed, a warning should certainly be safe.)
Per Bothner pointed out that simply issuing an error if the linker was invoked without --main would not be appropriate once C++ main programs are better supported with Java code.
Tom expressed some concerns about implied options. I wouldn't be at all opposed if this were not officially supported, and even in case 1 we issued a warning, but then did the right thing anyway. I think in case there really is only one "right thing". And it's important to do that, since it determines whether most user's first attempt to use gcj succeeds or fails. The warning would simultaneously teach users the proper way to invoke gcj for larger applications.
From: Dara Hazeghi <email@example.com>
Subject: Re: java/2370: Behavior of main compilation without --main is unfriendly
Date: Mon, 12 May 2003 11:03:47 -0700
Hans Boehm say:
"I originally filed 2370. I also think that one needs to remain open.
But it's clearly an RFE, not a bug report."
This report should remain open.
I would like this to be even more friendly. Ideally,
would generate --main automatically, as mentioned, and
would generate --main if there was only one main method in the source files or
fail with a message listing the possible main methods if there were more than one.
I don't know enough about the front-end yet to know how to do this, but ideally
this is how it should work. I suppose the driver would have to be able to
search source files (and probably .class files too) for main methods, so that it
would be able to offer a list of possibilities.