Cant compile java-gnome sample, it alsways says "undefined reference"

Tom Tromey tromey@redhat.com
Tue Jun 4 12:17:00 GMT 2002


>>>>> "Clemens" == Clemens Eisserer <Linuxhippy@web.de> writes:

Clemens> I tried to work with java-gnome (jni-bindings for gtk) and
Clemens> gcj (on the java-gnome homepage they said that this
Clemens> combination shouldwork).  The compilation of this bindings
Clemens> made an "gtk.jar" and an "libgtk.so.0.71". The lingtk.so.071
Clemens> is copied by "make install"into "/usr/lib" and the gtk.jar is
Clemens> in "/usr/local/share/java-gtk/gtk.jar".  When I want to
Clemens> compile now an test-sample with "gcj -fPIC -fjni -lGTKJAR (or
Clemens> even -lGTKJar) TestGTK.java -o testgtk -O -g
Clemens> --classpath=/usr/Share/gcc-3.0.4/libgcj.jar:/usr/local/share/java-gtk/gtk.jar",
Clemens> always this happens "usr/bin/ld cant find -lGTKJAR".

`-l' options must name libraries that contain object files.
In the above, there is no `libGTKJAR.a' or `libGTKJAR.so'.
The .so file you do have probably contains only the JNI functions --
not everything.

So what you must do is make a shared library containing objects built
from the java code.  Then you can link your program against that.

Clemens> I've also tried to make an library-file, and I did so. I
Clemens> compiled all java-files with "gcj -c Filename.java" and liked
Clemens> that with"objects=`find . -name '*.o'` gcj -shared $objects
Clemens> -o gnu.so" Then I got an gnu.so, but I dont know what to do
Clemens> with that?

You're pretty close here.  What you really want is to compile each
.java file with:

    gcj -fPIC -fjni -c Filename.java

`-fPIC' is used for shared libraries.  `-fjni' is required because
native methods in these classes are implemented using JNI, not CNI.

Then link all the .o files into a shared library:

    gcj -shared $objects -o libjava-gnome.so

Install this somewhere.

Finally, link your program against it:

    gcj -fjni --main=... TestGTK.java -o testgtk --classpath=... -ljava-gnome

HTH,
Tom



More information about the Java mailing list