This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: gcc to compile Java programs
On 03/15/2012 12:42 AM, raghavan Viswanathan wrote:
> I had downloaded and built the gcc-4.6.1 on my ubuntu linux. I had enabled the default languages during the configuration. So I have support for Java.
>
> I have a simple HelloWorld Java program.
>
> public class HelloWorld {
> public static void main(String [] args) {
> System.out.println("Hello");
> }
> }
>
>
> I am able to use the gcj driver program to compile the
> HelloWorld.java to generate a binary using the command
> gcj HelloWorld.java --main=HelloWorld -o HelloWorld -static -v
>
> However, when I try to use gcc as the driver it is not able to build
> a binary. After observing the options used by gcj driver, I was able
> to get get it past the compilations and assembly by supplying a huge
> number of options.
Well, don't do that, then. Use gcj.
> I see that the gcj uses the jvgenmain program to generate the main() program.
> /home/rags/my_gcc/gcc-4.6.1/libexec/gcc/i686-pc-linux-gnu/4.6.1/jvgenmain HelloWorldmain /tmp/ccYiuAkp.i
>
> The gcc driver is NOT invoking jvgenmain program to have the main()
> and hence it is not able to find the main()
That's correct.
> My question is
> (1) Is gcj the only way to compile java programs ? .
Yes,
> (2) Can we use the gcc driver to compile and link standalone Java
> programs ?
No.
Andrew.