Converting a JAR into a gcj-statically-linked SO
Andrew Haley
aph@redhat.com
Mon Jan 7 12:39:00 GMT 2008
Matthijs van de Water writes:
> I've been working with GCJ (4.2) to convert a JAR library into a Linux
> shared object for an embedded system in such a way that it does not
> depend on libgcj.
> Until now, I'm failing at producing the right commandline options to
> get this to link properly.
>
> Let me explain what I'm trying to do in some more detail:
> I have a JAR file which is in fact a library. I want to use this
> library on an embedded Linux system and make calls to it from a native
> application written in C/C++.
> There are _no_ other processes on the system that could benefit from
> libgcj.so, even if I had 33MB of space on my rootfs laying around
> (which I don't), so I want to statically link libgcj to the resulting
> native library. The API of the resulting library will totally hide
> anything Java related, so I was expecting to be able to link it to my
> application without needing libgcj.
>
> I've been reading similar requests on the list and the static linking
> WiKi page, but until now I've failed to get this to link (let alone
> work).
>
> My commandline is:
> gcj -save-temps -shared -fPIC -Wl,-Bsymbolic MyJavaLib.jar -o libmyjava.so
> gcc -o libmynative.so -shared -fPIC native_lib.cc MyJavaLib.o -lstdc++
> -shared-libgcc -Wl,-non_shared -lgcj -Wl,-call_shared -lsupc++
> -Wl,--as-needed -lz -lgcc_s -lpthread -lc -lm -ldl -Wl,--no-as-needed
>
> This produces a native SO (libmynative.so) which (according to readelf
> -d) does not depend on libgcj. So far so good.
>
> Unfortunately, I cannot get a simple test.cc program which uses the
> libmynative API (without any Java dependencies) to link. It always
> complains about missing references to java in libmynative.so.
> gcc -o test test.cc -lstdc++ -L . -lmynative
Tell us what messages *exactly*.
> Could anyone give me some pointers in the right direction?
> If I add "-lgcj" to the test program gcc line it does compile, but
> obviously depends on libgcj. Also, the resulting program does not work
> (crashes with a SEGV). When using only shared libraries, the test
> program works fine.
>
> Is what I try to do even feasible?
>
> I'm currently testing on my desktop (Ubuntu), but I'll be moving to an
> ARM embedded system if I get this working.
This is tricky to do, but not impossible. David Daney has some
experience in this area.
If you to produce a simple complete test case that we can try it'll be
much easier to help you.
Andrew.
--
Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, UK
Registered in England and Wales No. 3798903
More information about the Java
mailing list