I'm trying to build a java application with gcj but getting the error below. It's been a while since I've used gcj (a year or so), so I may have forgot something non obvious but I'm pretty sure this is how I've always done it.
multiple definition of `java resource .dummy'
gcj ver开发者_如何学运维sions are 4.4.1 on Ubuntu and 4.3.4 on cygwin/windows XP and I'm building it with
gcj --main=my.MainClass --classpath=my my/*java
Anyone seen this or know a workaround without installing an earlier version of gcj. If that is the way to do it does anyone know how to do that on cygwin or will I have to build it?
Here is a minimal test case that gives this error
public class A {
public static void main(String[] args) {
System.out.println(new B());
}
}
public class B {
public String toString() {
return "Hello";
}
}
gcj --main=A src/A.java src/B.java
There are 2 bugs filed against this 42143 and 43302
The only reported solution is to compile to class files, then link the class files.
The following produces no errors:
gcj -I src -C src/A.java src/B.java
gcj -I src --main=A src/A.class src/B/class
If you're building by compiling the .java files to .o files with gcj -c
, you can also fix the problem by making the dummy symbols local with objcopy:
objcopy -L '_ZGr8_$_dummy' A.o
This works well with a Makefile -- just add to the %.o: %.java
rule:
objcopy -L '_ZGr8_$$_dummy' $@
At least with some version of gcj, explicitly specifying the output executable using -o will make it work:
gcj --main=my.MainClass -o myexe --classpath=my my/*java
I have no explanation for this behaviour though.
Not a solution to the problem mentioned, but a way to compile to native code: 1. compile a jar archive using sun/openjdk 2. convert jar to executable using
gcj project.jar --main=package.name.ClassWithMainMethod
精彩评论