LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: blue_tomato on June 18, 2005, 04:04:59

Title: Native compilation with GCJ!
Post by: blue_tomato on June 18, 2005, 04:04:59
I have searched the forums about how to natively compile a LWJGL application with GCJ, but found only outdated references to some old GCJ bugs.

Have anyone successfully used GCJ with LWJGL now?

I believe GCJ compiled native code and JVM would be a perfect bundle with my LWJGL games. Fast, small, stand-alone and FREE (as opposed to the much advertised JET)

So far I have bundled the JRE from Sun with my games, adding an install shield for both JRE and game, but their license forces me to keep all kinds of crap I do not need in the rt.jar, like AWT, JDBC, CORBA etc. So, the download is huge, with maybe 90% being junk that is not needed by the game at all! Bandwidth is expensive, and my users are impatient with too low bandwidth at home, so this is not good at all! :(

My stand-alone GCJ programs are TINY compared to this, and also allows a lot of heavy optimizations not available for the realtime JIT compiler approach. I also like the ability to turn off out-of-bounds checks, that really speeds up my inner loops. Also, I like the added security and ease of deployment an exe file gives me.

I noticed this seems to have been solved with JOGL, but I prefer LWJGL. So, if this is possible please let me know how you did it! :)
Title: Native compilation with GCJ!
Post by: Matzon on June 18, 2005, 09:36:17
there has been some work done on this. the latest try hit some small snag, that Elias fixed very shortly after. I am not aware of the current startus beyond that.
Title: Native compilation with GCJ!
Post by: elias on June 19, 2005, 08:10:29
According to the latest thread about gcj:

http://lwjgl.org/forum/viewtopic.php?t=1129

it should work. I fixed the problem with AWTGLCanvas (I think  :), but in any case, Display should still work fine.

- elias
Title: Native compilation with GCJ!
Post by: blue_tomato on June 21, 2005, 03:25:06
Ok, happy to know this is solved. :)

I am a bit newbie with GCJ though, so do you mind to let me know how to compile up a simple example like

http://java-game-lib.sourceforge.net/wiki/tiki-index.php?page=Lesson+4

In fact, it compiles fine, but the linker complains about undefined references. Do I need some special version of the DLL to link properly?

I get (my test program is called HelloSWT, which launches the Lesson04 example)

C:\java\HelloSWT>gcj --main=HelloSWT -o HelloSWT *.o
HelloSWT.o: In function `ZN8HelloSWTC1Eb':
C:/java/HelloSWT/HelloSWT.java:65: undefined reference to `org::lwjgl::opengl::D
isplay::update()'
HelloSWT.o: In function `ZN8HelloSWT8mainloopEv':
C:/java/HelloSWT/HelloSWT.java:75: undefined reference to `org::lwjgl::input::Ke
yboard::poll()'
C:/java/HelloSWT/HelloSWT.java:76: undefined reference to `org::lwjgl::input::Ke
yboard::isKeyDown(int)'
C:/java/HelloSWT/HelloSWT.java:79: undefined reference to `org::lwjgl::opengl::D
isplay::isCloseRequested()'

.. etc

Do you know how to pass the linking stage successfully?

Thanks :)
Title: Native compilation with GCJ!
Post by: elias on June 21, 2005, 06:51:37
I'm on shaky grounds here, but I guess that you're missing the equivalent of -classpath. If you natively compiled lwjgl, can you compile your own stuff with something like gcj -o <app> -llwjgl?

- elias
Title: Native compilation with GCJ!
Post by: blue_tomato on June 21, 2005, 13:26:08
Quote from: "elias"I'm on shaky grounds here, but I guess that you're missing the equivalent of -classpath. If you natively compiled lwjgl, can you compile your own stuff with something like gcj -o <app> -llwjgl?

- elias

Not sure if I understand what you mean, but I do add the classpath during compilation.

The compiler is invoked by:


gcj --CLASSPATH=C:\java\lwjgl\jar\lwjgl.jar --no-bounds-check -O3 -c -g -O *.java

This produces the right HelloSWT.o file containing the compiled binary machine code (hopefully also the compiled code from the LWJGL.JAR file?), that is to be wrapped with the bundled Garbage collector etc. by the linker.

The linker is invoked by:


gcj --main=HelloSWT -o HelloSWT *.o

So, the full compile and linking process is as follows:


C:\java\HelloSWT>gcj --CLASSPATH=C:\java\lwjgl\jar\lwjgl.jar --no-bounds-check -
O3 -c -g -O *.java

C:\java\HelloSWT>gcj --main=HelloSWT -o HelloSWT *.o
HelloSWT.o: In function `ZN8HelloSWTC1Eb':
C:/java/HelloSWT/HelloSWT.java:65: undefined reference to `org::lwjgl::opengl::D
isplay::update()'
HelloSWT.o: In function `ZN8HelloSWT8mainloopEv':
C:/java/HelloSWT/HelloSWT.java:75: undefined reference to `org::lwjgl::input::Ke
yboard::poll()'
C:/java/HelloSWT/HelloSWT.java:76: undefined reference to `org::lwjgl::input::Ke
yboard::isKeyDown(int)'
C:/java/HelloSWT/HelloSWT.java:79: undefined reference to `org::lwjgl::opengl::D
isplay::isCloseRequested()'
C:/java/HelloSWT/HelloSWT.java:82: undefined reference to `org::lwjgl::input::Ke
yboard::isKeyDown(int)'
C:/java/HelloSWT/HelloSWT.java:86: undefined reference to `org::lwjgl::input::Ke
yboard::isKeyDown(int)'

...etc

So, all seems fine except the linking process. Seems like it cannot find the right references to the proper methods in the DLL file? Any ideas?

I am lost here, but I guess this should be quite trivial to solve if I just knew how to use GCJ properly... :)
Title: Native compilation with GCJ!
Post by: Matzon on June 21, 2005, 13:37:43
think the problem is that lwjgl.jar needs to be compiled at the same time too ?
Title: Native compilation with GCJ!
Post by: blue_tomato on June 21, 2005, 15:42:22
Quote from: "Matzon"think the problem is that lwjgl.jar needs to be compiled at the same time too ?

Maybe, I guess it is not smart enough to do that automatically as needed...

I tried


gcj -c lwjgl.jar


which gave


C:\java\HelloSWT>gcj -c lwjgl.jar
org/lwjgl/opengl/AWTGLCanvas.java:0: error: cannot find file for class java.awt.
event.HierarchyListener
org/lwjgl/opengl/AWTGLCanvas.java: In class 'org.lwjgl.opengl.AWTGLCanvas':
org/lwjgl/opengl/AWTGLCanvas.java: In constructor '(java.awt.GraphicsDevice,org.
lwjgl.opengl.PixelFormat,org.lwjgl.opengl.Drawable)':
org/lwjgl/opengl/AWTGLCanvas.java:60: error: cannot find file for class java.awt
.event.HierarchyListener
org/lwjgl/opengl/AWTGLCanvas.java:60: confused by earlier errors, bailing out


Seems to be a problem with AWT dependence now?
Title: Native compilation with GCJ!
Post by: blue_tomato on June 21, 2005, 16:25:58
Well, I solved the AWT problem by manually removing all classes that was infected with this problem.

Then I successfully produced the lwjgl.o file, and recompiling the main program now gives


C:\java\HelloSWT>gcj --main=HelloSWT -o HelloSWT *.o
lwjgl.o: In function `ZN3org5lwjgl6openal2AL6createEv':
C:/java/HelloSWT/lwjgl.jar:(.text+0x9bd3): undefined reference to `org::lwjgl::o
penal::AL::nCreate(JArray<java::lang::String*>*)'
C:/java/HelloSWT/lwjgl.jar:(.text+0x9be6): undefined reference to `org::lwjgl::o
penal::AL10::initNativeStubs()'
C:/java/HelloSWT/lwjgl.jar:(.text+0x9beb): undefined reference to `org::lwjgl::o
penal::ALC::initNativeStubs()'
C:/java/HelloSWT/lwjgl.jar:(.text+0x9bf8): undefined reference to `org::lwjgl::o
penal::ALC::alcOpenDevice(java::lang::String*)'
C:/java/HelloSWT/lwjgl.jar:(.text+0x9dcb): undefined reference to `org::lwjgl::o
penal::ALC::alcMakeContextCurrent(long long)'
lwjgl.o: In function `ZN3org5lwjgl6openal2AL7destroyEv':
C:/java/HelloSWT/lwjgl.jar:(.text+0x9e9c): undefined reference to `org::lwjgl::o
penal::ALC::alcDestroyContext(long long)'
C:/java/HelloSWT/lwjgl.jar:(.text+0x9ede): undefined reference to `org::lwjgl::o
penal::ALC::alcCloseDevice(long long)'
C:/java/HelloSWT/lwjgl.jar:(.text+0x9f30): undefined reference to `org::lwjgl::o
penal::AL::resetNativeStubs(java::lang::Class*)'
C:/java/HelloSWT/lwjgl.jar:(.text+0x9f78): undefined reference to `org::lwjgl::o
penal::AL::resetNativeStubs(java::lang::Class*)'
C:/java/HelloSWT/lwjgl.jar:(.text+0x9fb3): undefined reference to `org::lwjgl::o
penal::AL::nDestroy()'
lwjgl.o: In function `ZN3org5lwjgl6openal4AL1017alDopplerVelocityEf':
C:/java/HelloSWT/lwjgl.jar:(.text+0xa169): undefined reference to `org::lwjgl::o
penal::AL10::nalDopplerVelocity(float)'
lwjgl.o: In function `ZN3org5lwjgl6openal4AL1015alDopplerFactorEf':
C:/java/HelloSWT/lwjgl.jar:(.text+0xa193): undefined reference to `org::lwjgl::o

etc...

Well, no closer to solution, now I just get problems linking lwjgl instead of problems linking my own program... So much hassle, I have no idea now... :/
Title: Native compilation with GCJ!
Post by: AndersD on June 21, 2005, 16:46:26
If I remember correctly, gcj compiles java-native bindings as their own "special jni" by default - you probably need to specify -fjni (?)

EDIT: And as I've noticed you're trying this on windows - you should be aware that gcj can only link statically on windows (IIRC again ;). IMO: Basically the attitude among a lot of the developers on gcj  @ gnu mailing list is quite "anti-windowz" :P (not saying they're impolite if you ask any windows specific questions - just that they not really care about the windows implementation).
Title: Native compilation with GCJ!
Post by: blue_tomato on June 21, 2005, 17:21:31
Quote from: "AndersD"If I remember correctly, gcj compiles java-native bindings as their own "special jni" by default - you probably need to specify -fjni (?)

EDIT: And as I've noticed you're trying this on windows - you should be aware that gcj can only link statically on windows (IIRC again ;). IMO: Basically the attitude among a lot of the developers on gcj  @ gnu mailing list is quite "anti-windowz" :P (not saying they're impolite if you ask any windows specific questions - just that they not really care about the windows implementation).

Tried -fjni during linking, no luck.. :(

But, the MinGW team successfully added SWT to GCJ, so it should be possible to add LWJGL the same way...

Unfortunately my own JNI, GCJ and C++ skills are just very basic, I do not see any way out of this mess. Too bad, it would really be great to make this work.

Quite amazing something this simple is that hard... Sigh..

And about anti-windows fanatics, I do not dare to tread in their murky lairs, if you leave them alone with their Linux coding they harm noone... :)
Title: Native compilation with GCJ!
Post by: blue_tomato on June 21, 2005, 17:53:15
Woah, made it work now! :D

The trick was to add -fjni to all stages, not only during linking...

The compressed stand-alone distributable is now only 2mb, which is really great!

Now my only concern is about the AWT related methods I removed, but hopefully they are not really doing anything useful.

I suggest all AWT dependence is removed from LWJGL, having no AWT was in fact one of its greatest benefits earlier...
Title: Native compilation with GCJ!
Post by: princec on June 21, 2005, 19:55:48
They can be easily removed if you don't want to use them. Really we should supply them as a separate jar.

Cas :)
Title: Native compilation with GCJ!
Post by: AndersD on June 21, 2005, 20:13:20
Have you tried compiling lwjgl as a shared dll? Just curious if it will work :)
Title: Native compilation with GCJ!
Post by: blue_tomato on June 22, 2005, 11:55:14
Quote from: "AndersD"Have you tried compiling lwjgl as a shared dll? Just curious if it will work :)

Nope, did not try that. But it is a much better idea to use Proguard to link it all together before compiling, then all unused methods and classes are removed. I lost one megabyte of junk from the compressed distributable file this way! :)

My compressed stand-alone distributable is now only slightly over 1mb! It contains everything needed to run a simple openGL based animation, and consists only of one native EXE file and the lwjgl DLL file!

At least, I THINK it contains everything... Hard to know as the team behind GCJ does a fine job in NOT telling whether you need to bundle any DLLs with your GCJ compiled application or not. And after installing MinGV my system is polluted with all kinds of runtime DLLs so I do not know if it works in a clean system or not.

Give it a try if you want, I have put an example here:

http://www.ninjasoftware.com/download/standalone_test.rar

Please let me know if it works on your system, or wheter I need more DLLs with it...

Thanks! :)
Title: Native compilation with GCJ!
Post by: Matzon on June 22, 2005, 12:19:13
A window with a black background popped up, and immediately closed again... no errors or log files...
Title: Native compilation with GCJ!
Post by: AndersD on June 22, 2005, 14:06:36
Works for me (I think) - rotating triangle and square. (Main.exe + lwjgl.dll)

Nice indeed that gcj seems to be working now!
Title: Native compilation with GCJ!
Post by: tomb on June 22, 2005, 17:37:31
Worked for me too  :D
Title: Native compilation with GCJ!
Post by: Matzon on June 22, 2005, 17:54:16
:cry:
Title: Native compilation with GCJ!
Post by: oNyx on June 22, 2005, 18:36:06
Worked here, too. It also gets even better compressed with 7z (lzma).
Title: Native compilation with GCJ!
Post by: blue_tomato on June 22, 2005, 20:02:13
Sounds very promising !

Matzon, I put a new test for you here:

www.ninjasoftware.com/download/deploy_test2.rar

This one keeps the console window open while running, hopefully some error messages will show why you could not run it.

Also, this version opens a Hello World SWT window first. Then proceeds with the rotating triangle+square test. You can hit F1 to toggle between fullscreen and window mode.

So, now we have the full JVM with garbage collector, Java libraries, native exe file, LWJGL and SWT here, in only 1.5mb!

Sweet... :D
Title: Native compilation with GCJ!
Post by: princec on June 22, 2005, 20:53:31

1400 x 1050 x 16 @60Hz
1280 x 1024 x 16 @60Hz
480 x 360 x 16 @60Hz
640 x 480 x 16 @60Hz
400 x 300 x 32 @60Hz
512 x 384 x 16 @60Hz
320 x 240 x 32 @60Hz
1024 x 768 x 32 @60Hz
800 x 600 x 32 @60Hz
1280 x 1024 x 32 @60Hz
480 x 360 x 32 @60Hz
1400 x 1050 x 32 @60Hz
400 x 300 x 16 @60Hz
640 x 480 x 32 @60Hz
512 x 384 x 32 @60Hz
320 x 240 x 16 @60Hz
1024 x 768 x 16 @60Hz
800 x 600 x 16 @60Hz
Exception in thread "main" java.lang.ExceptionInInitializerError
  at 0x0043f56e (Unknown Source)
  at 0x0043ef02 (Unknown Source)
  at 0x005013a4 (Unknown Source)
  at 0x0043eb34 (Unknown Source)
  at 0x0050eb9c (Unknown Source)
  at 0x00446faf (Unknown Source)
  at 0x0058590e (Unknown Source)
  at 0x00589383 (Unknown Source)
  at 0x00446da4 (Unknown Source)
  at 0x004ef669 (Unknown Source)
  at 0x004ef810 (Unknown Source)
  at 0x004ef85f (Unknown Source)
  at 0x0043b57d (Unknown Source)
  at 0x00419938 (Unknown Source)
  at 0x004113c1 (Unknown Source)
  at 0x00413dd4 (Unknown Source)
  at 0x00414120 (Unknown Source)
  at 0x00419f20 (Unknown Source)
  at 0x004041cf (Unknown Source)
  at 0x00417329 (Unknown Source)
  at 0x004168d4 (Unknown Source)
  at 0x00417514 (Unknown Source)
  at 0x004173bf (Unknown Source)
  at 0x0041738d (Unknown Source)
  at 0x00401b5a (Unknown Source)
  at 0x00401f52 (Unknown Source)
  at 0x00401818 (Unknown Source)
  at 0x00401758 (Unknown Source)
  at 0x00468153 (Unknown Source)
  at 0x0044de40 (Unknown Source)
  at 0x0041fe36 (Unknown Source)
  at 0x0041ffb7 (Unknown Source)
  at 0x004012ca (Unknown Source)
  at 0x004011e3 (Unknown Source)
  at 0x00401234 (Unknown Source)
  at 0x7c816d4b (Unknown Source)
Caused by: java.util.MissingResourceException: Bundle gnu/regexp/MessagesBundle
not found
  at 0x0043f56e (Unknown Source)
  at 0x0043ef02 (Unknown Source)
  at 0x0043ab54 (Unknown Source)
  at 0x0043ed94 (Unknown Source)
  at 0x005c6115 (Unknown Source)
  at 0x005bbf5d (Unknown Source)
  at 0x005bbfea (Unknown Source)
  at 0x00588fd2 (Unknown Source)
  at 0x00446da4 (Unknown Source)
  ...30 more

Right after I click the close button on the Hello World window.

Cas :)
Title: Native compilation with GCJ!
Post by: Matzon on June 22, 2005, 21:21:20
same as princec
Title: Native compilation with GCJ!
Post by: Matzon on June 22, 2005, 22:26:57
hmm, tried to gcj org.lwjgl.examples.Game, failed miserably:
<?xml version="1.0"?>
<project name="lwjgl-native" default="default" basedir=".">

<taskdef resource="proguard/ant/task.properties" classpath="${ant.home}/lib/proguard.jar" />

<target name="default">
<proguard>
-libraryjars ${java.home}/lib/rt.jar
-injars      lib/lwjgl.jar;lib/lwjgl_test.jar;lib/lwjgl_util.jar;lib/lwjgl_fmod3.jar
-outjars     lwjgl-native.jar

-dontoptimize
-dontobfuscate

-keep public class org.lwjgl.examples.Game {
public static void main(java.lang.String[]);
}

-keepclasseswithmembernames class * {
}
</proguard>
</target>
</project>


Created my native jar file. I then removed the META-INF dir, since I was getting:
Quotejc1.exe: out of memory allocating 1852795252 bytes

Then I ran:gcj -fjni -c lwjgl-native.zip

and ended with:
gcj -L"c:\PROGRA~1\MICROS~3\lib" --main=org.lwjgl.examples.Game -o Game lwjgl-native.o

the -L"..." was because I was getting:
Quotec:\gcc4\gcc-4.0\bin\..\lib\gcc\i686-pc-mingw32\4.0.0\..\..\..\..\i686-pc-mingw32\bin\ld.exe: cannot find -lgdi32

The last command just resulted in 82 kBs of:
Quotec:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/../../../../i686-pc-mingw32/lib/crt2.o:crt1.c:(.text+0x112): undefined reference to `SetUnhandledExceptionFilter@4'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/../../../../i686-pc-mingw32/lib/crt2.o:crt1.c:(.text+0x1f2): undefined reference to `ExitProcess@4'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/libgcc.a(unwind-sjlj.o): In function `fc_key_init':
/datal/gcc/gcc/gcc/gthr-win32.h:566: undefined reference to `TlsAlloc@0'
/datal/gcc/gcc/gcc/gthr-win32.h:577: undefined reference to `GetLastError@0'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/libgcc.a(unwind-sjlj.o): In function `fc_key_init_once':
/datal/gcc/gcc/gcc/gthr-win32.h:539: undefined reference to `InterlockedIncrement@4'
/datal/gcc/gcc/gcc/gthr-win32.h:552: undefined reference to `Sleep@4'
/datal/gcc/gcc/gcc/gthr-win32.h:552: undefined reference to `Sleep@4'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/libgcc.a(unwind-sjlj.o): In function `uw_install_context':
/datal/gcc/gcc/gcc/gthr-win32.h:605: undefined reference to `TlsSetValue@8'
/datal/gcc/gcc/gcc/gthr-win32.h:605: undefined reference to `GetLastError@0'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/libgcc.a(unwind-sjlj.o): In function `Unwind_Backtrace':
/datal/gcc/gcc/gcc/gthr-win32.h:593: undefined reference to `GetLastError@0'
/datal/gcc/gcc/gcc/gthr-win32.h:595: undefined reference to `TlsGetValue@4'
/datal/gcc/gcc/gcc/gthr-win32.h:597: undefined reference to `SetLastError@4'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/libgcc.a(unwind-sjlj.o): In function `Unwind_SjLj_Unregister':
/datal/gcc/gcc/gcc/gthr-win32.h:605: undefined reference to `TlsSetValue@8'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/libgcc.a(unwind-sjlj.o): In function `Unwind_SjLj_Resume':
/datal/gcc/gcc/gcc/gthr-win32.h:593: undefined reference to `GetLastError@0'
/datal/gcc/gcc/gcc/gthr-win32.h:595: undefined reference to `TlsGetValue@4'
/datal/gcc/gcc/gcc/gthr-win32.h:597: undefined reference to `SetLastError@4'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/libgcc.a(unwind-sjlj.o): In function `Unwind_SjLj_ForcedUnwind':
/datal/gcc/gcc/gcc/gthr-win32.h:593: undefined reference to `GetLastError@0'
/datal/gcc/gcc/gcc/gthr-win32.h:595: undefined reference to `TlsGetValue@4'
/datal/gcc/gcc/gcc/gthr-win32.h:597: undefined reference to `SetLastError@4'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/libgcc.a(unwind-sjlj.o): In function `Unwind_SjLj_RaiseException':
/datal/gcc/gcc/gcc/gthr-win32.h:593: undefined reference to `GetLastError@0'
/datal/gcc/gcc/gcc/gthr-win32.h:595: undefined reference to `TlsGetValue@4'
/datal/gcc/gcc/gcc/gthr-win32.h:597: undefined reference to `SetLastError@4'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/libgcc.a(unwind-sjlj.o): In function `Unwind_SjLj_Resume_or_Rethrow':
/datal/gcc/gcc/gcc/gthr-win32.h:593: undefined reference to `GetLastError@0'
/datal/gcc/gcc/gcc/gthr-win32.h:595: undefined reference to `TlsGetValue@4'
/datal/gcc/gcc/gcc/gthr-win32.h:597: undefined reference to `SetLastError@4'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/libgcc.a(unwind-sjlj.o): In function `Unwind_SjLj_Register':
/datal/gcc/gcc/gcc/gthr-win32.h:593: undefined reference to `GetLastError@0'
/datal/gcc/gcc/gcc/gthr-win32.h:595: undefined reference to `TlsGetValue@4'
/datal/gcc/gcc/gcc/gthr-win32.h:597: undefined reference to `SetLastError@4'
/datal/gcc/gcc/gcc/gthr-win32.h:605: undefined reference to `TlsSetValue@8'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/libgcc.a(unwind-sjlj.o): In function `Unwind_SjLj_Unregister':
/datal/gcc/gcc/gcc/gthr-win32.h:605: undefined reference to `GetLastError@0'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/libgcc.a(unwind-sjlj.o): In function `Unwind_SjLj_Register':
/datal/gcc/gcc/gcc/gthr-win32.h:605: undefined reference to `GetLastError@0'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/../../../../i686-pc-mingw32/lib/libgcj.a(natThread.o):natThread.cc:(.text+0x41): undefined reference to `InitializeCriticalSection@4'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/../../../../i686-pc-mingw32/lib/libgcj.a(natThread.o):natThread.cc:(.text+0xa4): undefined reference to `DeleteCriticalSection@4'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/../../../../i686-pc-mingw32/lib/libgcj.a(natThread.o):natThread.cc:(.text+0x28e): undefined reference to `Sleep@4'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/../../../../i686-pc-mingw32/lib/libgcj.a(natThread.o):natThread.cc:(.text+0x3ff): undefined reference to `TlsGetValue@4'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/../../../../i686-pc-mingw32/lib/libgcj.a(natThread.o):natThread.cc:(.text+0x41f): undefined reference to `TlsGetValue@4'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/../../../../i686-pc-mingw32/lib/libgcj.a(natThread.o):natThread.cc:(.text+0x7f0): undefined reference to `EnterCriticalSection@4'
c:/gcc4/gcc-4.0/bin/../lib/gcc/i686-pc-mingw32/4.0.0/../../../../i686-pc-mingw32/lib/libgcj.a(natThread.o):natThread.cc:(.text+0x7f8): undefined reference to `GetCurrentThreadId@0'
etc etc etc
[/i]
Title: Native compilation with GCJ!
Post by: blue_tomato on June 23, 2005, 03:03:39
Quote from: "Matzon"...
Created my native jar file. I then removed the META-INF dir, since I was getting:
Quotejc1.exe: out of memory allocating 1852795252 bytes
...

GCJ has a silly bug that causes it to run out of memory if trying to compile a JAR file generated by Proguard. I guess as you remove some entries, you are forcing it to update and clear some fatal flags or something.

I solved this by building this JAR file again using the JAR command from the JDK.


echo **Repackage jar file as workaround for GCJ out-of-memory bug
rmdir temp /s/q
md temp
copy output_proguard.jar temp
cd temp
jar xf output_proguard.jar
del output_proguard.jar
jar cf output_proguard.jar .
copy output_proguard.jar .. /y
cd ..
rmdir temp /s/q


I guess the GCJ team did not feel it was confusing enough already, and wanted to add some more fun challenges ;)

The proguard step is also quite sensitive. I spent quite a long time to tune the settings to something not removing anything important:


-injars       output.jar;c:\java\lwjgl\jar\lwjgl.jar
-outjars      output_proguard.jar
-libraryjars  <java.home>/lib/rt.jar;c:\java\swt\swt.jar
-printmapping proguard.map
-overloadaggressively
-defaultpackage ''
-allowaccessmodification
-dontobfuscate
-dontoptimize
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers

-keep public class Main {
   public static void main(java.lang.String[]);
}

-keep class org.lwjgl.opengl.Win32Display
-keep class org.lwjgl.opengl.DisplayMode {*;}
-keep class org.lwjgl.Win32SysImplementation
-keep class org.lwjgl.opengl.Win32ContextImplementation


Pay especially attention to the keep statements. And the dontskip* statements, they are important for keeping the required code.

Note, I am using the MinGW version of GCJ, which has SWT built in. That is why I do not add it to the output jar like lwjgl in the example above.

I also got

cannot find -lgdi32

at first. I never really figured out the specific reason, but it disappeared after I installed the MinGW version of GCJ instead of the "normal" GCJ.

You can find this version here:

http://www.thisiscool.com/gcc_mingw.htm

But it seems like you are already using it? Did you use their installer? Seems to install some libraries needed properly.

Anyway, let me know if any of this solves the problem... :)
Title: Native compilation with GCJ!
Post by: blue_tomato on June 23, 2005, 03:26:47
Quote from: "princec"
1400 x 1050 x 16 @60Hz
1280 x 1024 x 16 @60Hz
480 x 360 x 16 @60Hz
640 x 480 x 16 @60Hz
400 x 300 x 32 @60Hz
512 x 384 x 16 @60Hz
320 x 240 x 32 @60Hz
1024 x 768 x 32 @60Hz
800 x 600 x 32 @60Hz
1280 x 1024 x 32 @60Hz
480 x 360 x 32 @60Hz
1400 x 1050 x 32 @60Hz
400 x 300 x 16 @60Hz
640 x 480 x 32 @60Hz
512 x 384 x 32 @60Hz
320 x 240 x 16 @60Hz
1024 x 768 x 16 @60Hz
800 x 600 x 16 @60Hz
Exception in thread "main" java.lang.ExceptionInInitializerError
  at 0x0043f56e (Unknown Source)
  at 0x0043ef02 (Unknown Source)
  at 0x005013a4 (Unknown Source)
  at 0x0043eb34 (Unknown Source)
  at 0x0050eb9c (Unknown Source)
  at 0x00446faf (Unknown Source)
  at 0x0058590e (Unknown Source)
  at 0x00589383 (Unknown Source)
  at 0x00446da4 (Unknown Source)
  at 0x004ef669 (Unknown Source)
  at 0x004ef810 (Unknown Source)
  at 0x004ef85f (Unknown Source)
  at 0x0043b57d (Unknown Source)
  at 0x00419938 (Unknown Source)
  at 0x004113c1 (Unknown Source)
  at 0x00413dd4 (Unknown Source)
  at 0x00414120 (Unknown Source)
  at 0x00419f20 (Unknown Source)
  at 0x004041cf (Unknown Source)
  at 0x00417329 (Unknown Source)
  at 0x004168d4 (Unknown Source)
  at 0x00417514 (Unknown Source)
  at 0x004173bf (Unknown Source)
  at 0x0041738d (Unknown Source)
  at 0x00401b5a (Unknown Source)
  at 0x00401f52 (Unknown Source)
  at 0x00401818 (Unknown Source)
  at 0x00401758 (Unknown Source)
  at 0x00468153 (Unknown Source)
  at 0x0044de40 (Unknown Source)
  at 0x0041fe36 (Unknown Source)
  at 0x0041ffb7 (Unknown Source)
  at 0x004012ca (Unknown Source)
  at 0x004011e3 (Unknown Source)
  at 0x00401234 (Unknown Source)
  at 0x7c816d4b (Unknown Source)
Caused by: java.util.MissingResourceException: Bundle gnu/regexp/MessagesBundle
not found
  at 0x0043f56e (Unknown Source)
  at 0x0043ef02 (Unknown Source)
  at 0x0043ab54 (Unknown Source)
  at 0x0043ed94 (Unknown Source)
  at 0x005c6115 (Unknown Source)
  at 0x005bbf5d (Unknown Source)
  at 0x005bbfea (Unknown Source)
  at 0x00588fd2 (Unknown Source)
  at 0x00446da4 (Unknown Source)
  ...30 more

Right after I click the close button on the Hello World window.

Cas :)

Doh!

Did you also try the first test:

http://www.ninjasoftware.com/download/standalone_test.rar

It is without the swt... Hm, seems like swt is working fine though, as you get the Hello World window....

Also, the lwjgl binding seems to be working fine too, as you get the output of display modes available on your system...

Does other lwjgl applications work for you in 800x600 @16 bpp windowed mode?


Caused by: java.util.MissingResourceException: Bundle gnu/regexp/MessagesBundle
not found

What the h*** is that? Missing what resource now?  :?

What system are you running on?
Title: Native compilation with GCJ!
Post by: blue_tomato on June 23, 2005, 06:41:38
New test:

www.ninjasoftware.com/download/deploy_test3.rar

Adds much more detailed debug output, and also a display resolution selector so it is possible to try various settings, in case that is the problem.

Please give it a spin, and let me know what you discover...

Thanks! :)

Oh, by the way. I noticed LWJGL returns several impossible display settings. My laptop can only show 1024x768 pixels, but in fact LWJGL returned 768x1024 as a valid mode? When selecting this in fullscreen mode, mouse movement was rotated 90 degrees, and rendering was garbled... Windowed mode seems to be working ok though...

Any way to get only the modes that will actually work in a fullscreen environment?
Title: Native compilation with GCJ!
Post by: Matzon on June 23, 2005, 09:02:42
cant extract test 3
Title: Native compilation with GCJ!
Post by: Matzon on June 23, 2005, 09:50:33
I installed MinGW and libiconv, and now I get:
QuoteException in thread "main" java.lang.NoClassDefFoundError: org.lwjgl.Sys
  at 0x0045ea6e (Unknown Source)
  at 0x0045ef62 (Unknown Source)
  at 0x0049f304 (Unknown Source)
  at 0x004587a4 (Unknown Source)
  at 0x0045e4c4 (Unknown Source)
  at 0x0046bbf1 (Unknown Source)
  at 0x00660545 (Unknown Source)
  at 0x004037f4 (Unknown Source)
  at 0x00407465 (Unknown Source)
  at 0x0046b988 (Unknown Source)
  at 0x00660545 (Unknown Source)
  at 0x00407136 (Unknown Source)
  at 0x00403fdf (Unknown Source)
  at 0x00403e03 (Unknown Source)
  at 0x004d9051 (Unknown Source)
  at 0x00484fbe (Unknown Source)
  at 0x00466f20 (Unknown Source)
  at 0x00454ee7 (Unknown Source)
  at 0x00454fb7 (Unknown Source)
  at 0x004012ca (Unknown Source)
  at 0x004011e3 (Unknown Source)
  at 0x00401234 (Unknown Source)
  at 0x7c816d4b (Unknown Source)
despite my zip file containing the class ?
Title: Native compilation with GCJ!
Post by: blue_tomato on June 23, 2005, 13:41:14
Quote from: "Matzon"cant extract test 3

Argh, damn that pretend-to-be broadband I am on here, the upload got broken. :(

Should work now:

www.ninjasoftware.com/download/deploy_test3.rar
Title: Native compilation with GCJ!
Post by: Matzon on June 23, 2005, 14:57:00
Test 3
I get to select mode, window pops up, and boom - exit
Perhaps print some stuff to console to check where it crashes ?
QuoteAvailable display modes:
1280 x 800 x 32 @60Hz
1360 x 768 x 32 @75Hz

LOTS

1600 x 1024 x 32 @72Hz
1088 x 612 x 32 @70Hz
1600 x 1024 x 16 @70Hz
Exception in thread "main" java.lang.ExceptionInInitializerError
*** Got java.lang.NullPointerException while trying to print stack trace.
Title: Native compilation with GCJ!
Post by: blue_tomato on June 23, 2005, 15:40:42
Quote from: "Matzon"Test 3
I get to select mode, window pops up, and boom - exit
Perhaps print some stuff to console to check where it crashes ?
QuoteAvailable display modes:
1280 x 800 x 32 @60Hz
1360 x 768 x 32 @75Hz

LOTS

1600 x 1024 x 32 @72Hz
1088 x 612 x 32 @70Hz
1600 x 1024 x 16 @70Hz
Exception in thread "main" java.lang.ExceptionInInitializerError
*** Got java.lang.NullPointerException while trying to print stack trace.

Hm, I do print quite a lot of info when an exception is caught. But from the error it seems like the exception itself is causing a new exception to be thrown?

I have put the source code here:

www.ninjasoftware.com/download/src.rar
Title: Native compilation with GCJ!
Post by: blue_tomato on June 24, 2005, 04:07:57
I have compiled a new test which will output more debug information, so it should be possible to pinpoint where the problem occurs on some systems

www.ninjasoftware.com/download/deploy_test4.rar
Title: Native compilation with GCJ!
Post by: Matzon on June 24, 2005, 05:35:28
Quote[init]
[createWindow]
Exception in thread "main" java.lang.ExceptionInInitializerError
  at 0x0044d56e (Unknown Source)
  at 0x0044cf02 (Unknown Source)
  at 0x0050f9e4 (Unknown Source)
  at 0x0044cb94 (Unknown Source)
  at 0x0051d1dc (Unknown Source)
  at 0x0045500f (Unknown Source)
  at 0x00591bbe (Unknown Source)
  at 0x00595633 (Unknown Source)
  at 0x00454e04 (Unknown Source)
  at 0x004fde69 (Unknown Source)
  at 0x004fe010 (Unknown Source)
  at 0x004fe05f (Unknown Source)
  at 0x004495dd (Unknown Source)
  at 0x0041a108 (Unknown Source)
  at 0x00411b91 (Unknown Source)
  at 0x004145a4 (Unknown Source)
  at 0x004148f0 (Unknown Source)
  at 0x0041a6f0 (Unknown Source)
  at 0x0040499f (Unknown Source)
  at 0x00417af9 (Unknown Source)
  at 0x004170a4 (Unknown Source)
  at 0x00417ce4 (Unknown Source)
  at 0x00417b8f (Unknown Source)
  at 0x00417b5d (Unknown Source)
  at 0x00402323 (Unknown Source)
  at 0x00402649 (Unknown Source)
  at 0x00401e6c (Unknown Source)
  at 0x00401762 (Unknown Source)
  at 0x004761b3 (Unknown Source)
  at 0x0045bea0 (Unknown Source)
  at 0x00420606 (Unknown Source)
  at 0x00420787 (Unknown Source)
  at 0x004012ca (Unknown Source)
  at 0x004011e3 (Unknown Source)
  at 0x00401234 (Unknown Source)
  at 0x7c816d4b (Unknown Source)
Caused by: java.util.MissingResourceException: Bundle gnu/regexp/MessagesBundle not found
  at 0x0044d56e (Unknown Source)
  at 0x0044cf02 (Unknown Source)
  at 0x00448bb4 (Unknown Source)
  at 0x0044cdf4 (Unknown Source)
  at 0x0060d465 (Unknown Source)
  at 0x005c820d (Unknown Source)
  at 0x005c829a (Unknown Source)
  at 0x00595282 (Unknown Source)
  at 0x00454e04 (Unknown Source)
  ...30 more

Is it possible to make stacktrace lines work in gcj ?
Could you post the source + scripts to generate the exe, then I could debug easily myself
Title: Native compilation with GCJ!
Post by: blue_tomato on June 24, 2005, 07:41:40
Quote from: "Matzon"
Quote[init]
[createWindow]
Exception in thread "main" java.lang.ExceptionInInitializerError
  at 0x0044d56e (Unknown Source)
  at 0x0044cf02 (Unknown Source)
  at 0x0050f9e4 (Unknown Source)
  at 0x0044cb94 (Unknown Source)
  at 0x0051d1dc (Unknown Source)
  at 0x0045500f (Unknown Source)
  at 0x00591bbe (Unknown Source)
  at 0x00595633 (Unknown Source)
  at 0x00454e04 (Unknown Source)
  at 0x004fde69 (Unknown Source)
  at 0x004fe010 (Unknown Source)
  at 0x004fe05f (Unknown Source)
  at 0x004495dd (Unknown Source)
  at 0x0041a108 (Unknown Source)
  at 0x00411b91 (Unknown Source)
  at 0x004145a4 (Unknown Source)
  at 0x004148f0 (Unknown Source)
  at 0x0041a6f0 (Unknown Source)
  at 0x0040499f (Unknown Source)
  at 0x00417af9 (Unknown Source)
  at 0x004170a4 (Unknown Source)
  at 0x00417ce4 (Unknown Source)
  at 0x00417b8f (Unknown Source)
  at 0x00417b5d (Unknown Source)
  at 0x00402323 (Unknown Source)
  at 0x00402649 (Unknown Source)
  at 0x00401e6c (Unknown Source)
  at 0x00401762 (Unknown Source)
  at 0x004761b3 (Unknown Source)
  at 0x0045bea0 (Unknown Source)
  at 0x00420606 (Unknown Source)
  at 0x00420787 (Unknown Source)
  at 0x004012ca (Unknown Source)
  at 0x004011e3 (Unknown Source)
  at 0x00401234 (Unknown Source)
  at 0x7c816d4b (Unknown Source)
Caused by: java.util.MissingResourceException: Bundle gnu/regexp/MessagesBundle not found
  at 0x0044d56e (Unknown Source)
  at 0x0044cf02 (Unknown Source)
  at 0x00448bb4 (Unknown Source)
  at 0x0044cdf4 (Unknown Source)
  at 0x0060d465 (Unknown Source)
  at 0x005c820d (Unknown Source)
  at 0x005c829a (Unknown Source)
  at 0x00595282 (Unknown Source)
  at 0x00454e04 (Unknown Source)
  ...30 more

Is it possible to make stacktrace lines work in gcj ?
Could you post the source + scripts to generate the exe, then I could debug easily myself

This means the code fails here:


       if (DEBUG) System.out.println("[createWindow]");
       try {
           Display.setDisplayMode(mode);
       } catch (LWJGLException e) {
           System.out.println("Failed to initialize the display at display mode " + mode.toString());
           System.out.println(e.toString());
           e.printStackTrace();
           return;
       }

       Display.create();
       Display.setFullscreen(fullscreen);

       //sync frame (only works on windows) and linux apparently
       Display.setVSyncEnabled(true);
       Display.setTitle(animator.getName() + " " + animator.getVersion());
       if (DEBUG) System.out.println("[/createWindow]");


My guess is the problem is

       Display.setDisplayMode(mode);


I already posted a link to the source code earlier ( www.ninjasoftware.com/download/src.rar ), and the build script is:


@echo off

set exename=Main.exe
set main=Main
set deploy=_deploy

echo **Compiling Java files...
rmdir classes /s/q
md classes
javac -classpath c:\java\lwjgl\jar\lwjgl.jar;c:\java\swt\swt.jar -d classes src\*.java src\engine\*.java

echo **Creating JAR...
cd classes
jar Mcf ..\output.jar *.class engine\*.class
cd ..

echo **Removing unused methods...
java -classpath C:\java\proguard\lib\proguard.jar proguard.ProGuard @proguard.pro

echo **Repackage jar file as workaround for GCJ out-of-memory bug
rmdir temp /s/q
md temp
copy output_proguard.jar temp
cd temp
jar xf output_proguard.jar
del output_proguard.jar
jar cf output_proguard.jar .
copy output_proguard.jar .. /y
cd ..
rmdir temp /s/q

echo **Compiling to machine code...
gcj -fjni --no-bounds-check -O3 -c output_proguard.jar

echo **Linking...
rem add -mwindows to remove the console window
gcj -fjni --main=%main% -o %exename% *.o

echo **Building deploy directory
rmdir %deploy% /s/q
md %deploy%
copy %exename% %deploy%
copy C:\java\lwjgl\native\lwjgl.dll %deploy%
copy C:\gcc\i686-pc-mingw32\lib\swt-win32-3116.dll %deploy%

pause

echo **Cleaning up
del output.jar
del output_proguard.jar
del output_proguard.o
del %exename%


The Proguard script is


-injars       output.jar;c:\java\lwjgl\jar\lwjgl.jar
-outjars      output_proguard.jar
-libraryjars  <java.home>/lib/rt.jar;c:\java\swt\swt.jar
-printmapping proguard.map
-overloadaggressively
-defaultpackage ''
-allowaccessmodification
-dontobfuscate
-dontoptimize
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers

-keep public class Main {
   public static void main(java.lang.String[]);
}

-keep class org.lwjgl.opengl.Win32Display
-keep class org.lwjgl.opengl.DisplayMode {*;}
-keep class org.lwjgl.Win32SysImplementation
-keep class org.lwjgl.opengl.Win32ContextImplementation

About stacktrace in gcj, sorry, I do not know. But now you have everything I have, and hopefully you can localize the problem more efficiently... :)
Title: Native compilation with GCJ!
Post by: Matzon on June 28, 2005, 21:54:09
got it!

I am just going to tell you what the problem was, I cannot tell you why it is so, it just is - I am as confused as I can get...

The crash occurs in: GLContext.java, in the getPlatformSpecificFunctionAddress method.

Specifically, it crashes on the line:
String platform_function_name = function.replaceFirst(function_prefix, os_function_prefixes);

HOWEVER (and this is where it gets funny (did I mention it took a looong time to locate?)) it ONLY occurs when locating methods for : NV_vertex_array_range_initNativeFunctionAddresses, specifically:
glFreeMemoryNV, glAllocateMemoryNV and so forth.

The replaceFirst method is meant to replace gl from  glFreeMemoryNV with wgl, becomming: wglFreeMemoryNV.

If I manually change the function.replace... line to:
String platform_function_name = "w" + function;
then *everything* works fine

:?:

I am totally, completely at a loss as to what is going on - and I have absolutely no idea why it is happening only when running under GCJ, but *somehow* the GCJ code must act weird in some strange corner cases, or something along those lines. (but only on my computer (nVidia))

So, you're code works fine - except for the ghost in the shell.
Title: Native compilation with GCJ!
Post by: blue_tomato on June 29, 2005, 03:19:23
Quote from: "Matzon"got it!

I am just going to tell you what the problem was, I cannot tell you why it is so, it just is - I am as confused as I can get...

The crash occurs in: GLContext.java, in the getPlatformSpecificFunctionAddress method.

Specifically, it crashes on the line:
String platform_function_name = function.replaceFirst(function_prefix, os_function_prefixes);

HOWEVER (and this is where it gets funny (did I mention it took a looong time to locate?)) it ONLY occurs when locating methods for : NV_vertex_array_range_initNativeFunctionAddresses, specifically:
glFreeMemoryNV, glAllocateMemoryNV and so forth.

The replaceFirst method is meant to replace gl from  glFreeMemoryNV with wgl, becomming: wglFreeMemoryNV.

If I manually change the function.replace... line to:
String platform_function_name = "w" + function;
then *everything* works fine

:?:

I am totally, completely at a loss as to what is going on - and I have absolutely no idea why it is happening only when running under GCJ, but *somehow* the GCJ code must act weird in some strange corner cases, or something along those lines. (but only on my computer (nVidia))

So, you're code works fine - except for the ghost in the shell.

And I assume your Proguard compiled JAR file will run well, even when you keep the lwjgl.jar away from the classpath?

If not, my first guess would be that Proguard somehow figured out that your platform specific program running path would never occur and thus removed required methods.

This is a quite common problem with Proguard, and any kinds of dynamically loaded code must be included manually.

How about adding


-keep class org.lwjgl.opengl.GLContext {*;}


Or, try compile with different Proguard settings? Like turn off


-overloadaggressively
-allowaccessmodification


Or, maybe compile with less optimization (omit -O3 and removal of bounds checks)?

Just guessing really, sounds very strange....  :roll:
Title: Native compilation with GCJ!
Post by: blue_tomato on July 01, 2005, 22:57:26
By the way, do you mind putting the GCJ workaround into the next release of the API?

Thanks :)