Static executables

David Daney ddaney@avtrex.com
Tue Jan 31 16:59:00 GMT 2006


Andrzej Bialecki wrote:

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

As APH said, I don't think -findirect-dispatch should be here.  As far 
as I know it works only with dynamic loading of gcj compiled .so files. 
    JNI will probably still work, but I have not tried it.

> gcj -c charva.jar -fjni -findirect-dispatch -o charva.o

Same thing.

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

That is not right.  All your objects MUST come before the -lgcj part of 
the link line.

> Some other observations: I didn't need to link -lgcc_s, in fact I don't 
> have it anywhere...

You must have it somewhere.  It is part of gcc.  You do need it. If you 
do not have it, exceptions will not work.  The -shared-libgcc probably 
forces it to be linked so that leaving off the explict -lgcc_s changes 
nothing.


David Daney



More information about the Java mailing list