.java to .exe on win32 with Cygwin

# 2003-09-26 08:39:47 -0400 | Java | 13 Comments

I updated my Cygiwn installation last night and noticed that I now have gcj, the “ahead-of-time compiler for the Java language”. Unable to resist, I coded up a “hello world” program.

$ ls
Test.java
$ uname -a
CYGWIN_NT-5.0 tiny 1.5.5(0.94/3/2) 2003-09-20 16:31 i686 unknown unknown Cygwin
$ cat Test.java
public class Test {
    public static void main(String[] args)  {
        System.out.println(”Hello, world!”);
    }
}
$ gcj –main=Test -o Test Test.java
$ ls
Test.exe  Test.java
$ ./Test
Hello, world!

Cool. Also, I belive gcj is availiable in the MinGW 3.3.1 release candidate. MingGW allows you to use the gcc tools on win32 “without cygwin.dll”. Maybe someone needs to compile up a native version of Eclipse on win32. ;-)

13 Responses to this entry:

  1. Ashwin Jayaprakash Says:

    See http://www.thisiscool.com/gcc_mingw.htm.

    Regards,
    Ashwin.

  2. Neil Weber Says:

    How big is the .exe?

  3. Anonymous Coward Says:

    Natively Compiled Eclipse for Linux:
    http://sources.redhat.com/eclipse/

  4. Matt Quail Says:

    The .exe is about 2.5 MB. I assume that represents alot of "overhead".


    $ ls -l Test.exe
    -rwxrwxrwx 1 matt None 2723868 Sep 26 08:32 Test.exe

  5. bjd Says:

    makes me want to install cygwin again now. used to use it ages ago but had moral issues with trying to make my non-unix based OS look like unix.
    but i’m willing to give it a shot again. i hate windows enough to make it happen.

  6. Does NOT work for me Says:

    % uname -a
    CYGWIN_NT-5.0 SKANGA-W2K3 1.5.5(0.94/3/2) 2003-09-20 16:31 i686 unknown unknown Cygwin

    % cat Test.java
    public class Test {
    public static void main(String[] args) {
    System.out.println("Hello, world!");
    }
    }

    % gcj –main=Test -o Test Test.java
    /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/../../../../i686-pc-cygwin/bin/ld: cannot
    find -liconv
    collect2: ld returned 1 exit status

    Maybe I need to install something else? Any ideas

  7. Matt Quail Says:

    You can install libiconv via the Cygwin setup.exe

  8. arun Says:

    le tme test it

  9. arun Says:

    Let me test it

  10. driss Says:

    $ gcj –main=Test -o Test Test.java
    /cygdrive/c/DOCUME~1/DANOUNOU/LOCALS~1/Temp/ccg9iXyc.o(.text+0×39): In function main':
    /cygdrive/c/DOCUME~1/DANOUNOU/LOCALS~1/Temp/ccLDUFzr.i: undefined reference to
    Test::class$’
    collect2: ld returned 1 exit status

  11. Matt Quail Says:

    worked for me:
    $ gcj –main=Test -o Test Test.java
    $ ./Test.exe
    Hello, world!
    $ gcj –version
    gcj (GCC) 3.3.1 (cygming special)

  12. Mizos Says:

    Can you compile GUI applications?

  13. dozens Says:

    Ok, I insalled libiconv and can not build and run Test.java within ming32. Is there anyway to staticly link in libiconv so I run the executable from dos ?

Leave a Reply

Click here to leave a reply