Investigating cross-platform development options, I found that Java can be a nice option for cross-platform GUI. Especially, I liked the idea of SWT, which is based on native graphic libraries, GTK for Linux and MFC for windows.
And what is indeed cool - SWT application can be compiled into native executable by gcj compiler.
I did it for my Eclipse-written SWT application.
There are few steps to perform it (I did in on Windows in MinGW environment)
1. Install suitable GCJ distribution - I used ThisIsCool distribution built especially for MinGW,
but any other can be used as well
2. Recompile SWT libraries - actually what we need is to receive libswt.a library for static linking. One can use already compiled library, but if doesn't match swt version you use, you can face some troubles with GUI look.
3. Unzip the jar file your Eclipse uses into some directory. All you need here is the java .class files
4. Run the next script, that will build object files from each class file and pack it into libswt.a library
#!/bin/sh
SWT_CLASSES=`find . -name "*.class" -print sed 's/^\.\///'`
for i in $SWT_CLASSES
do
OBJ_FILE=`echo $i sed 's/\//_/g' sed 's/\.class$/\.o/'`
echo Compiling $i to $OBJ_FILE gcj -fjni -g0 -c -o $OBJ_FILE $i
done
gcj -c --resource=org.eclipse.swt.internal.SWTMessages \ -o SWTMessages.o org/eclipse/swt/internal/SWTMessages.properties
echo Creating libswt.a
OBJ_FILES=`ls *.o`
for i in $OBJ_FILES
do ar rvs libswt.a $i
done
ranlib libswt.a
echo Done.
5. Now go to the directory your application java class is placed, copy there libswt.a, swt.jar and swt-win32-xxxx.dll
6. Compile the executable file - assume your class is named Moca_VE.java:
i686-pc-mingw32-gcj -fjni --main=Moca_VE -s --classpath swt.jar -o Moca_VE.exe Moca_VE.java -s -L. -Wl,--no-whole-archive -lswt -mwindows
Saturday, July 19, 2008
Subscribe to:
Posts (Atom)