Make sure that:
#1: you're calling System.loadLibrary(someLib) [ I'm assuming you are ]
#2: when you compile your native library, you are exporting the symbols
you need to call from your Java program [ this was a real pain in the
butt on a Mac ]
Peter Gutowski wrote:
>
> 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
--
Jeff Galyan
http://www.anamorphic.com
http://www.sun.com
jeffrey dot galyan at sun dot com
talisman at anamorphic dot com
Sun Certified Java(TM) Programmer
======================================================================
Linus Torvalds on Microsoft and software development:
"... if it's a hobby for me and a job for you, why are you doing such a
shoddy job of it?"
The views expressed herein do not necessarily reflect those of my
employer.
Sun Microsystems, Inc., has no connection to my involvement with the
Mozilla Organization.