Compiling lwjgl with gcj - almost...

Started by AndersD, April 28, 2004, 11:47:02

Previous topic - Next topic

AndersD

Hello, I've now tried compiling lwjgl with gcj-3.4 (recently released) and it's getting very close (I'm on linux btw).

This is what I've done so far (if you spot any errors please let me know):
Installed gcc3.4:
../gcc-3.4.0/configure --prefix=/opt/gcc-3.4.0 --enable-shared --enable-languages=java --enable-threads=posix --enable-long-long --enable-version-specific-runtime-libs --enable-nls --x-includes=/usr/X11R6/include/ --x-libraries=/usr/X11R6/lib/ --enable-interpreter --enable-java-awt=gtk --with-x --disable-multilib
Thread model: posix
gcc version 3.4.0


Compiled lwjgl from source (cvs version from a couple of days or so)
* Deleted references to org.w3c (they are implemented in 3.4 - but a hassle to link with)
* Deleted SwingAdapter (referenced an unimplemented showMessageDialog method)

Compiled lwjgl.jar with gcj into object file (-fjni as default gcj native linkage method is cni):
/opt/.../gcj -c -fjni lwjgl.jar


Linked lwjgl.so to a shared library liblwjgl_native.so:
/opt/.../gcj -o liblwjgl_native.so -fjni -Wl liblwjgl.so lwjgl.o


* Remember to copy liblwjgl_native.so and liblwjgl.so to /usr/lib and soft linking /opt/.../lib/gcjlib.so.5 to /usr/lib too.

So far, all seems to be working.

Here comes the troublesome part:
Tried to compile a test program
import org.lwjgl.Display;
import org.lwjgl.DisplayMode;
import org.lwjgl.opengl.Window;

public class Test {

    public static void main(String[] args) {
        // Test creation/destruction of window

        try {
            Window.create("LWJGL Game Example");
            Thread.sleep(100);
            System.out.println("Created OpenGL: 1");
            Thread.sleep(1000);

            Window.destroy();
            Thread.sleep(100);
            System.out.println("Window destroy: 1");
        } catch (Exception e) {
            System.err.println("Failed due to " + e);
            System.exit(1);
        }
    }
}

Compiling and linking.
/opt/.../gcj -c -fjni --classpath=.:lwjgl.jar Test.java
/opt/.../gcj -o test -fjni -Wl liblwjgl_native.so --main=Test Test.o

Running:
Exception in thread "main" java.lang.NoSuchMethodError: nglCallLists
   at ext_InitializeClass(JNIEnv_, _jclass, _jobject, byte const, void ()(byte const), int, JavaMethodAndExtFunction) (/usr/lib/liblwjgl.so)
   at extgl_InitializeClass (/usr/lib/liblwjgl.so)
   at extgl_InitOpenGL1_1(JNIEnv_) (/usr/lib/liblwjgl.so)
   at extgl_Initialize (/usr/lib/liblwjgl.so)
   at Java_org_lwjgl_opengl_GLContext_init (/usr/lib/liblwjgl.so)
   at org.lwjgl.opengl.GLContext.init(java.util.Set) (/usr/lib/liblwjgl_native.so)
   at org.lwjgl.opengl.GLContext.useContext(java.lang.Object) (/usr/lib/liblwjgl_native.so)
   at org.lwjgl.opengl.Window.makeCurrent() (/usr/lib/liblwjgl_native.so)
   at org.lwjgl.opengl.Window.createWindow(int, int, int, int, int) (/usr/lib/liblwjgl_native.so)
   at org.lwjgl.opengl.Window.create(java.lang.String, int, int, int, int, int) (/usr/lib/liblwjgl_native.so)
   at org.lwjgl.opengl.Window.create(java.lang.String) (/usr/lib/liblwjgl_native.so)
   at Test.main(java.lang.String[]) (Unknown Source)


Solvable problem?

AndersD

Btw, the same problem when interpreting with gij:
anders@taif libs $ /opt/gcc-3.4.0/bin/gij -C --classpath=.:lwjgl.jar Test.java
anders@taif libs $ /opt/gcc-3.4.0/bin/gij -classpath .:lwjgl.jar Test
Exception in thread "main" java.lang.NoSuchMethodError: nglCallLists
   at ext_InitializeClass(JNIEnv_, _jclass, _jobject, byte const, void ()(byte const), int, JavaMethodAndExtFunction) (/usr/lib/liblwjgl.so)
   at extgl_InitializeClass (/usr/lib/liblwjgl.so)
   at extgl_InitOpenGL1_1(JNIEnv_) (/usr/lib/liblwjgl.so)
   at extgl_Initialize (/usr/lib/liblwjgl.so)
   at Java_org_lwjgl_opengl_GLContext_init (/usr/lib/liblwjgl.so)
   at _Jv_JNIMethod.call(ffi_cif, void, ffi_raw, void) (/opt/gcc-3.4.0/lib/libgcj.so.5.0.0)
   at org.lwjgl.opengl.GLContext.useContext(java.lang.Object) (Unknown Source)
   at org.lwjgl.opengl.Window.makeCurrent() (Unknown Source)
   at org.lwjgl.opengl.Window.createWindow(int, int, int, int, int) (Unknown Source)
   at org.lwjgl.opengl.Window.create(java.lang.String, int, int, int, int, int) (Unknown Source)
   at org.lwjgl.opengl.Window.create(java.lang.String) (Unknown Source)
   at Test.main(java.lang.String[]) (Unknown Source)

elias

Seems like a bug in gcj to me. If you take a look in extgl_InitOpenGL11 in ...GL11.cpp you'll see that nglCallLists is the first native method with a buffer object in the signature (Ljava/nio/Buffer;), so either the signature format is wrong (doesn't seem like it) or else gcj is (wrongly) unable to locate the method.

http://java.sun.com/docs/books/tutorial/native1.1/implementing/method.html

gives some pointers as to how method signatures are encoded, maybe you should try a

java -s -p GL11

on GL11.class to get the expected signature on nglCallLists.

- elias

AndersD

Got a reply to my post to java@gcc.gnu.org:

Quote
Anders,

The problem seems to be due to a bug in our JNI RegisterNatives implementation. I'd like to debug it further but the JNI shared lib in the lwjgl distribution lacks debugging symbols and the source distribution lacks a "configure" (and I dont want mess with autoconf!). Can you point me at a complete source distribution?

Thanks

Bryce

elias?

elias

The CVS version is complete. If he fetches a current CVS and does:

./autogen.sh
./configure
make

it should work.

You can test it yourself to make sure you give him the correct directions.

- elias

Smiley

Is there anything new on the subject from the GNU gcj people ?  :?:
Thx :)

AndersD

Yeah, there is a person looking into it now (he has retrieved the source etc etc) and has "confirmed" that it's probably a bug in gcj.

Hobbes

Getting this to work would be absolutely great. Good work!!

guurk

Any new info on this?

AndersD

Nope, but I posted a follow up to the fellow at redhat today, asking for more information. Hopefully he'll respond shortly and we'll know if it has been fixed in cvs or how long it will take!

AndersD

And thus he replies, looking like it will be fixed eventaully!

Quote
Hi Anders

I found at least 2 problems with gcj's JNI that were causing problems for lwjgl:

First was a bug with RegisterNatives - I have a fix for this somewhere but havn't had a chance to check it in, yet.

Second is the JNI functions for direct nio buffers (GetDirectBufferAddress etc). These functions don't actually work at all and need some changes to the classes in java.nio to work properly. Ideally, fairly major changes are needed in order to implement direct buffers more efficiently.

Unfortunately I got diverted onto other tasks and havn't had a chance to finish this stuff up yet, but I agree it could make for some cool demos so I'll try to work on it soon. I'll try to get the JNI fixes done at least, which should allow lwjgl to run even in the current java.nio will be slowing it down.

Regards

Bryce