This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Converting a JAR into a gcj-statically-linked SO
- From: "Matthijs van de Water" <matthijs dot van dot de dot water at gmail dot com>
- To: java at gcc dot gnu dot org
- Date: Mon, 7 Jan 2008 09:36:59 +0100
- Subject: Converting a JAR into a gcj-statically-linked SO
Hello,
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
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.
Thanks,
--
Regards,
Matthijs van de Water