Native compilation with GCJ!

Started by blue_tomato, June 18, 2005, 04:04:59

Previous topic - Next topic

Matzon

A window with a black background popped up, and immediately closed again... no errors or log files...

AndersD

Works for me (I think) - rotating triangle and square. (Main.exe + lwjgl.dll)

Nice indeed that gcj seems to be working now!

tomb


Matzon


oNyx

Worked here, too. It also gets even better compressed with 7z (lzma).

blue_tomato

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

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 :)

Matzon


Matzon

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]

blue_tomato

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... :)

blue_tomato

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?

blue_tomato

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?

Matzon


Matzon

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 ?

blue_tomato

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