* Using libraries - CNI and JNI
@ 2014-04-12 9:37 Jan Knezik
2014-04-12 17:46 ` Bryce McKinlay
0 siblings, 1 reply; 2+ messages in thread
From: Jan Knezik @ 2014-04-12 9:37 UTC (permalink / raw)
To: java
Hello guys,
I have some questions about GCJ:
1. Is it possible to compile and get work together main programme and
.so library (both written in Java) with GCJ using CNI or JNI?
2. I have the following code:
public class Test {
static {
System.loadLibrary("Test");
}
public native void hello();
public static void main(String[] args) {
new Test().hello();
}
}
I tried to compile it with "gcj Test.java --main=Test -o Test.bin". I got:
/tmp/ccWZkOjd.o:(.data+0x50): undefined reference to `hidden alias for
void Test::hello()'
/tmp/ccWZkOjd.o:(.data+0xc8): undefined reference to `hidden alias for
void Test::hello()'
I did not use "-fjni" so CNI should have been set. Where is the problem,
please? Thank you.
Jan Knezik
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Using libraries - CNI and JNI
2014-04-12 9:37 Using libraries - CNI and JNI Jan Knezik
@ 2014-04-12 17:46 ` Bryce McKinlay
0 siblings, 0 replies; 2+ messages in thread
From: Bryce McKinlay @ 2014-04-12 17:46 UTC (permalink / raw)
To: Jan Knezik; +Cc: GCC Java
On Sat, Apr 12, 2014 at 10:36 AM, Jan Knezik <jan.kn@email.cz> wrote:
> 1. Is it possible to compile and get work together main programme and .so library (both written in Java) with GCJ using CNI or JNI?
It is certainly possible to have a Java program split between a main
binary and .so libraries.
However CNI and JNI are for native methods (implemented in C++ or C
respectively), not when both parts are written in Java.
> 2. I have the following code:
>
> public class Test {
> static {
> System.loadLibrary("Test");
> }
>
> public native void hello();
>
> public static void main(String[] args) {
> new Test().hello();
> }
> }
>
> I tried to compile it with "gcj Test.java --main=Test -o Test.bin". I got:
>
> /tmp/ccWZkOjd.o:(.data+0x50): undefined reference to `hidden alias for void Test::hello()'
> /tmp/ccWZkOjd.o:(.data+0xc8): undefined reference to `hidden alias for void Test::hello()'
>
> I did not use "-fjni" so CNI should have been set. Where is the problem, please? Thank you.
For CNI, you need to tell the linker to link against the library
(static or shared) that contains the C++ implementation of hello().
For example, if hello() is in "libTest.so":
gcj Test.java --main=Test -o Test.bin -lTest
You can do the same thing is libTest.so was a library containing Java
code. However, you can't split a single class across different
libraries or implement a "native" method in Java.
Bryce
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-04-12 17:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-12 9:37 Using libraries - CNI and JNI Jan Knezik
2014-04-12 17:46 ` Bryce McKinlay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).