This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Static executables
David Daney wrote:
Tom Tromey wrote:
It would be helpful if someone wrote a page for the gcc wiki about
static linking.
Like this:?
http://gcc.gnu.org/wiki/Statically%20linking%20libgcj
I tested it now with some simple classes, it works well ... but I
suspect I'm still missing something, because my target application
doesn't work. I.e. it compiles and links ok, but fails during runtime.
I'm trying to compile a tutorial application for Charva
(http://www.pitman.co.za/projects/charva/). The library consists of a
JAR and some JNI parts, which use NCurses. When linking dynamically,
they are put in an libTerminal.so, and then the toolkit loads them with
System.loadLibrary("Terminal"). Now, with static linking, I thought this
no longer is needed, because I'm linking directly with these objects, so
I skipped the call to loadLibrary. But the application refuses to work,
throwing an UnsatisfiedLinkError to one of the symbols from that
library... Of course, if I keep the call to loadLibrary, the system
cannot find the library, so it dies anyway.
Here's the procedure I followed to prepare the library JAR, and the JNI
part:
# this depends on ncurses, but we're not linking now
gcj -c Toolkit.c -fjni -findirect-dispatch -o Toolkit.o
gcj -c charva.jar -fjni -findirect-dispatch -o charva.o
And then the magic incantation, copied from the Wiki (I put my objects
on separate lines for readability):
gcj -classpath charva.jar -c Test.java -o Test.o
gcj -classpath charva.jar --main=Test -save-temps Test.java
gcc -o Test Test.o Testmain.i -shared-libgcc -Wl,-non_shared -lgcj \
charva.o Toolkit.o \
-Wl,-call_shared -lsupc++ -Wl,--as-needed -lz -lpthread -lc -lm -ldl \
-lncurses \
-Wl,--no-as-needed
The application is linked properly, but then when executed, where it
calls the Charva library initialization, it fails because it cannot find
the native function from Terminal.o ... What to do now?
Some other observations: I didn't need to link -lgcc_s, in fact I don't
have it anywhere... Also, I believe there are no ready-made packages for
Fedora Core that contain libgcj.a, so I had to build it from the source.
And finally, the executable size is, well .. impressive, ~9MB for a
Hello World.
--
Best regards,
Andrzej Bialecki <><
___. ___ ___ ___ _ _ __________________________________
[__ || __|__/|__||\/| Information Retrieval, Semantic Web
___|||__|| \| || | Embedded Unix, System Integration
http://www.sigram.com Contact: info at sigram dot com