HOWTO Compile with gcj

TODO: Convert to the MediaWiki formatting as discussed at Converting Old MinGWiki Pages

When you first download and install the MinGW Java compiler (gcc-java), you may find that when you try to compile a Java program with gcj, you get an error saying "cannot find -liconv". This is because gcj automatically attempts to link your program with libiconv, which is not distributed with MinGW and must be downloaded and installed separately. To get your Java program to compile, download libiconv from http://gnuwin32.sourceforge.net/packages/libiconv.htm. You want "Binaries" and "Developer files". Unzip both downloaded files to your MinGW directory.

You should now be able to successfully compile a Java program. You might try the following as an example. Type this code into a file named Test.java:

public class Test
{
  public static void main(String args[])
  {
    System.out.println("This is a test.");
  }
}

Now compile it:

gcj --main=Test Test.java

There should now be a file named a.exe in the directory where you compiled the program. Run it and you should get the following output:

This is a test.

Re: HOWTO Compile with gcj

My g++ will compile and the .exe runs in windows 7.
My gcj will create .class files that runs.
Using the code:

public class Test
{

  public static void main(String args[])
  {
    System.out.println("This is a test.");
  }

}

and:
"gcj --main=Test Test.java" or "gcj --main=Test -o Test.exe Test.java"

Creates an .exe file, but when I run it
I get the error "a.exe (or Test.exe) has stopped working".
This also happens when I attempt to
run the file using the Windows XP compatibilty fix.

I will reboot to my XP partition and try it again, but you may want to add something that says this doesn't work in x64 if thats the case.

Site Status

Site maintenance completed May 25th, 2012 at 12:38 UTC