我的一个C函数如:void f(); 
封闭在libJNI.so中。
那我的JAVA程序如何调用f()函数呢?

解决方案 »

  1.   

    编译时报错啊:gcc -I$JAVA_HOME/include -I$JAVA_HOME/include/linux -fPIC -c Hello.c
    cat Hello.c
    [code]#include "Hello.h"
    #include <stdio.h>//与Hello.h中函数声明相同
    JNIEXPORT void JNICALL Java_Hello_SayHello(JNIEnv * env, jobject arg, jstring instring)
    {
        //从instring字符串取得指向字符串UTF编码的指针
        const jbyte *str = (const jbyte *)env->GetStringUTFChars(instring, JNI_FALSE);    printf("Hello, %s\n",str);    //通知虚拟机本地代码不再需要通过str访问Java字符串。
        env->ReleaseStringUTFChars(instring, (const char *)str);    return;
    }[/code]ello.c: In function `Java_Hello_SayHello':
    Hello.c:8: request for member `GetStringUTFChars' in something not a structure or union
    Hello.c:13: request for member `ReleaseStringUTFChars' in something not a structure or union
    我是按网上的例子来的,为什么别人可以,我的不行?
      

  2.   

    编译是通过了,但不知道为什么运行时出错,好像不能用System.loadLibrary("hello");来加载hello.so动态库么?java.lang.UnsatisfiedLinkError: /home/jstudy/src/jni/libhello.so: /home/jstudy/src/jni/libhello.so: undefined symbol: __gxx_personality_v0
      

  3.   

    echo $LD_LIBRARY_PATH
    .:/home/jstudy/src/jni:/home/jstudy/lib:/home/sybase/OCS-12_5/lib:路径应该是对的亚。我用的是System.loadLibrary("hello");
      

  4.   

    http://www.itwenzhai.com/data/2006/0621/article_25044.htm
    看看这个