I've used Cay Horstmann's and Gary Cornell "Core Java" books and have been
pretty happy with them. The second volume claims to help you create native
methods that can be called from java code. Their examples use Solaris and
WindozNT only though..
The instructions for using javah -jni to create a .h file are clear.
Everything seems quite smooth until I try to run the java program that
calls the C code. Here's what I get:
$ java HelloNative
@@Native.so: ELF file's phentsize not the expected size
(libHelloNative.so)
java.lang.UnsatisfiedLinkError: greeting
at HelloNative.main(HelloNative.java:10)
$
I'm guess I'm not sure what compile options I need to be using to make
java happy. My Make file (currently) looks something like this:
libHelloNative.so: HelloNative.c HelloNative.h
gcc -c -o libHelloNative.so \
-static \
-I/usr/java/include \
-I/usr/java/include/genunix \
HelloNative.c
The java program calling the C function is quite simple:
public class HelloNative {
public native static void greeting();
static {
System.loadLibrary ( "HelloNative" );
}
public static void main ( String args[] ) {
HelloNative hn = new HelloNative();
hn.greeting();
}
}
The C program is equally simple:
#include "HelloNative.h"
#include <stdio.h>
JNIEXPORT void JNICALL Java_HelloNative_greeting
( JNIEnv *env, jclass cl) {
printf ( "Hello Native World" );
}
All of this is *similar* to the example in the book but I am not sure what
I need to do to make it work. Any ideas?
Peter Gutowski
email: [EMAIL PROTECTED]
http://www.powervue.com/~peterg