.java to .exe on win32 with Cygwin

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 Comments

  1. Ashwin Jayaprakash
    Posted September 26, 2003 at 9:47 am | Permalink

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

    Regards,
    Ashwin.

  2. Posted September 26, 2003 at 3:55 pm | Permalink

    How big is the .exe?

  3. Anonymous Coward
    Posted September 26, 2003 at 5:27 pm | Permalink

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

  4. Posted September 26, 2003 at 10:08 pm | Permalink

    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
    Posted September 27, 2003 at 1:23 am | Permalink

    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
    Posted September 27, 2003 at 5:32 pm | Permalink

    % 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. Posted September 28, 2003 at 8:15 am | Permalink

    You can install libiconv via the Cygwin setup.exe

  8. arun
    Posted November 22, 2003 at 7:42 pm | Permalink

    le tme test it

  9. arun
    Posted November 22, 2003 at 7:43 pm | Permalink

    Let me test it

  10. driss
    Posted May 25, 2004 at 4:36 pm | Permalink

    $ 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. Posted May 25, 2004 at 11:41 pm | Permalink

    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
    Posted May 29, 2004 at 2:42 pm | Permalink

    Can you compile GUI applications?

  13. dozens
    Posted January 10, 2005 at 9:00 pm | Permalink

    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 ?

Post a Comment

Your email is never shared. Required fields are marked *

*
*