Bug 2370 - Behavior of main compilation without --main is unfriendly
Summary: Behavior of main compilation without --main is unfriendly
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 3.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2001-03-23 15:56 UTC by hans_boehm
Modified: 2016-09-30 22:52 UTC (History)
4 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2005-09-23 22:55:51


Note You need to log in before you can comment on or make changes to this bug.
Description hans_boehm 2001-03-23 15:56:00 UTC
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

gcj X.java

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.

gcc 3.0


gcj hello.java
Comment 1 Dara Hazeghi 2003-05-12 11:03:47 UTC
From: Dara Hazeghi <dhazeghi@yahoo.com>
To: gcc-gnats@gcc.gnu.org
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.
Comment 2 Thomas Fitzsimmons 2004-10-01 16:27:57 UTC
I would like this to be even more friendly.  Ideally,

gcj X.java

would generate --main automatically, as mentioned, and

gcj *.java

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.
Comment 3 Andrew Pinski 2016-09-30 22:52:08 UTC
Closing as won't fix as the Java front-end has been removed from the trunk.