当前位置: 技术问答>linux和unix
我看到在gcc的帮助文档可以编译java文件,我试了可以编译,但出错,不知道为什么.
来源: 互联网 发布时间:2015-05-06
本文导语: 程序如下: public class a { public static void main(String[] args) { System.out.println("asdfas"); } } 编译方法: gcc -x java a.java 错误如下: /usr/lib/gcc-lib/i386-redhat-linux/3.2/../../../crt1.o: In function `_start': /usr/lib/gcc-l...
程序如下:
public class a
{
public static void main(String[] args)
{
System.out.println("asdfas");
}
}
编译方法:
gcc -x java a.java
错误如下:
/usr/lib/gcc-lib/i386-redhat-linux/3.2/../../../crt1.o: In function `_start':
/usr/lib/gcc-lib/i386-redhat-linux/3.2/../../../crt1.o(.text+0x18): undefined reference to `main'
/tmp/ccivwqtu.o: In function `a::main(JArray*)':
/tmp/ccivwqtu.o(.text+0xf): undefined reference to `_Jv_InitClass'
/tmp/ccivwqtu.o(.text+0x18): undefined reference to `java::lang::System::class$'
/tmp/ccivwqtu.o(.text+0x2d): undefined reference to `java::lang::System::class$'
/tmp/ccivwqtu.o(.text+0x32): undefined reference to `_Jv_InitClass'
/tmp/ccivwqtu.o(.text+0x3e): undefined reference to `java::lang::System::out'
/tmp/ccivwqtu.o: In function `a::a[in-charge]()':
/tmp/ccivwqtu.o(.text+0x68): undefined reference to `java::lang::Object::Object[in-charge]()'
/tmp/ccivwqtu.o(.data+0x50): undefined reference to `java::lang::Object::finalize()'
/tmp/ccivwqtu.o(.data+0x54): undefined reference to `java::lang::Object::hashCode()'
/tmp/ccivwqtu.o(.data+0x58): undefined reference to `java::lang::Object::equals(java::lang::Objec t*)'
/tmp/ccivwqtu.o(.data+0x5c): undefined reference to `java::lang::Object::toString()'
/tmp/ccivwqtu.o(.data+0x60): undefined reference to `java::lang::Object::clone()'
/tmp/ccivwqtu.o(.data+0x80): undefined reference to `vtable for java::lang::Class'
/tmp/ccivwqtu.o(.data+0x94): undefined reference to `java::lang::Object::class$'
/tmp/ccivwqtu.o(.eh_frame+0x11): undefined reference to `__gcj_personality_v0'
collect2: ld returned 1 exit status
public class a
{
public static void main(String[] args)
{
System.out.println("asdfas");
}
}
编译方法:
gcc -x java a.java
错误如下:
/usr/lib/gcc-lib/i386-redhat-linux/3.2/../../../crt1.o: In function `_start':
/usr/lib/gcc-lib/i386-redhat-linux/3.2/../../../crt1.o(.text+0x18): undefined reference to `main'
/tmp/ccivwqtu.o: In function `a::main(JArray*)':
/tmp/ccivwqtu.o(.text+0xf): undefined reference to `_Jv_InitClass'
/tmp/ccivwqtu.o(.text+0x18): undefined reference to `java::lang::System::class$'
/tmp/ccivwqtu.o(.text+0x2d): undefined reference to `java::lang::System::class$'
/tmp/ccivwqtu.o(.text+0x32): undefined reference to `_Jv_InitClass'
/tmp/ccivwqtu.o(.text+0x3e): undefined reference to `java::lang::System::out'
/tmp/ccivwqtu.o: In function `a::a[in-charge]()':
/tmp/ccivwqtu.o(.text+0x68): undefined reference to `java::lang::Object::Object[in-charge]()'
/tmp/ccivwqtu.o(.data+0x50): undefined reference to `java::lang::Object::finalize()'
/tmp/ccivwqtu.o(.data+0x54): undefined reference to `java::lang::Object::hashCode()'
/tmp/ccivwqtu.o(.data+0x58): undefined reference to `java::lang::Object::equals(java::lang::Objec t*)'
/tmp/ccivwqtu.o(.data+0x5c): undefined reference to `java::lang::Object::toString()'
/tmp/ccivwqtu.o(.data+0x60): undefined reference to `java::lang::Object::clone()'
/tmp/ccivwqtu.o(.data+0x80): undefined reference to `vtable for java::lang::Class'
/tmp/ccivwqtu.o(.data+0x94): undefined reference to `java::lang::Object::class$'
/tmp/ccivwqtu.o(.eh_frame+0x11): undefined reference to `__gcj_personality_v0'
collect2: ld returned 1 exit status
|
你需要安装java的开发包,同时需要指出路径参数。