I can compile .java file without problem: gcc -c Y.java and Y.o file is created. But when trying to create executable (no -c) gcc Y.java I get: /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o: In function `_start': /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o(.text+0x18): undefined reference to `main' /tmp/ccKn35ww.o: In function `Y::Y(void)': /tmp/ccKn35ww.o(.text+0xe): undefined reference to `java::lang::Object::Object(void)' /tmp/ccKn35ww.o: In function `Y::main(JArray<java::lang::String *> *)': /tmp/ccKn35ww.o(.text+0x28): undefined reference to `_CL_Q34java4lang6System' /tmp/ccKn35ww.o(.text+0x3c): undefined reference to `_Jv_InitClass' /tmp/ccKn35ww.o(.text+0x4d): undefined reference to `_CL_Q34java4lang6System' /tmp/ccKn35ww.o(.text+0x52): undefined reference to `_Jv_InitClass' /tmp/ccKn35ww.o(.text+0x5e): undefined reference to `java::lang::System::err' /tmp/ccKn35ww.o: In function `global constructors keyed to Y::Y(void)': /tmp/ccKn35ww.o(.text+0x93): undefined reference to `_Jv_RegisterClass' /tmp/ccKn35ww.o(.data+0x38): undefined reference to `java::lang::Object::finalize(void)' /tmp/ccKn35ww.o(.data+0x3c): undefined reference to `java::lang::Object::hashCode(void)' /tmp/ccKn35ww.o(.data+0x40): undefined reference to `java::lang::Object::equals(java::lang::Object *)' /tmp/ccKn35ww.o(.data+0x44): undefined reference to `java::lang::Object::toString(void)' /tmp/ccKn35ww.o(.data+0x48): undefined reference to `java::lang::Object::clone(void)' /tmp/ccKn35ww.o(.data+0x60): undefined reference to `java::lang::Class virtual table' /tmp/ccKn35ww.o(.data+0x74): undefined reference to `_CL_Q34java4lang6Object' collect2: ld returned 1 exit status
Do you have libgcj installed?
Yes, I have rpm -q libgcj libgcj-devel libgcj-2.96-20 libgcj-devel-2.96-20
In addition: This is the file HelloWorld.java I am trying to compile: --- public class HelloWorld { public static void main(String [] args) { System.err.println("Hello, World"); } } ---
Make sure you pass it --main=HelloWorld option, see Java FAQ at http://sources.redhat.com/
GCC does not work with --main gcc --main=HelloWorld HelloWorld.java jc1: Unrecognized option `-fmain=HelloWorld' and gcj does not work at all because of bug http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=15349
You have to use gcj. The bug you mentioned has been fixed since then, for now just add libgcj.spec by hand: [jakub@pork 2.96]$ cd /usr/lib/gcc-lib/i386-redhat-linux/2.96/ [jakub@pork 2.96]$ cat libgcj.spec # # This spec file is read by gcj when linking. # It is used to specify the standard libraries we need in order # to link with libgcj. # %rename lib liborig *lib: -lgcj -lm -lgcjgc -lpthread -lzgcj -ldl %(liborig) *jc1: -fno-use-divide-subroutine -fasynchronous-exceptions # # libgcc should really be a shared library. This is a design flaw # that causes no end of mysterious problems. If we are using the # GNU linker, force parts of libgcc into the program file rather # than picking bits up from various shared libraries. # %rename startfile startfileorig *startfile: %(startfileorig) -u __rethrow -u __frame_state_for -lgcc
so this is fixed jakub? If so, please close.