Compile with gcj

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: Compile with gcj

when i compile and run the helloworld program, it's not printing "This is a test.", what's wrong? Please help, I'm using :
1. gcc 3.4.5
2. gcc-java-3.4.5
3. binutils-2.19.1-mingw32-bin
4. gcc-core-3.4.5
5. mingw-utils-0.3
6. mingwrt-3.15.2-mingw32-dev
7. mingwrt-3.15.2-mingw32-dll
8. w32api-3.13-mingw32-dev
9. libiconv-1.13-mingw32-bin
10. libiconv-1.13-mingw32-dev
11. libiconv-1.13-mingw32-dll-2

Re: Compile with gcj

keith's picture

So, there may be a problem with the instructions here, or with your interpretation of them. I don't know, as I have no experience of programming in java, but this isn't the place to ask for help; please use the mailing list for that.

When we have resolved your issue, through appropriate discussion there, we can update this article to address it.

Re: Compile with gcj

I just started using java diameter on LAMP doing some development work

Re: Compile with gcj

Has anyone gotten this to work on Vista? I followed the insturctions but I can not get the test java program to compile. I keep getting the error the instruction warn about.
Thanks.

Re: Compile with gcj

keith's picture

Why does this point to the GnuWin32 implementation of libiconv, when we do, in fact, provide our own?
https://sourceforge.net/project/showfiles.php?group_id=2435&package_id=67879

Files:
libiconv-1.11-1-bin.tar.bz2
libiconv-1.11-1-dll.tar.bz2
libiconv-1.11-1-src.tar.bz2

Re: Compile with gcj

earnie's picture

It was a direct copy from the old wiki. There are more than one reference to gnuwin32 that needs to change throughout this documentation.

Re: Compile with gcj

keith's picture

I thought it would be something like that; thanks for the confirmation.

Issues like this do highlight that that some packages, currently grouped into the MSYS Supplementary Tools collection, really deserve a more general exposure; libiconv would seem to be one such.

Site Status

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