我把生成的libcsscrypt.so 文件放到了 jre/lib/i386下了,程序能找到,但是在执行LoadLibrary时报如下的异常;Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/lib/jvm/java-6-sun-1.6.0.00/jre/lib/i386/libcsscrypt.so: /usr/lib/jvm/java-6-sun-1.6.0.00/jre/lib/i386/libcsscrypt.so: undefined symbol: _ZNSt8ios_base4InitC1Ev
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1668)
        at java.lang.Runtime.loadLibrary0(Runtime.java:823)
        at java.lang.System.loadLibrary(System.java:1030)
        at CryptDemo.<clinit>(CryptDemo.java:20)
Java Result: 1我实在dll里的cpp文件中对javah生成的头文件做的实现,javah生成的头文件如下:/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class CryptDemo */#ifndef _Included_CryptDemo
#define _Included_CryptDemo
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     CryptDemo
 * Method:    InitCrypt
 * Signature: (ILjava/lang/String;I)Z
 */
JNIEXPORT jboolean JNICALL Java_CryptDemo_InitCrypt
  (JNIEnv *, jclass, jint, jstring, jint);/*
 * Class:     CryptDemo
 * Method:    Encrypt
 * Signature: (Ljava/lang/String;IZ)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_CryptDemo_Encrypt
  (JNIEnv *, jclass, jstring, jint, jboolean);/*
 * Class:     CryptDemo
 * Method:    Decrypt
 * Signature: (Ljava/lang/String;IZ)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_CryptDemo_Decrypt
  (JNIEnv *, jclass, jstring, jint, jboolean);/*
 * Class:     CryptDemo
 * Method:    ReleaseCrypt
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_CryptDemo_ReleaseCrypt
  (JNIEnv *, jclass);#ifdef __cplusplus
}
#endif
#endif就四个方法.java jni调用文件如下:/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 *///package cssencrypt;/**
 *
 * @author wind
 */
public class CryptDemo {
    static
    {
        try
        {            System.loadLibrary("csscrypt");
        }
        catch(Exception e)
        {
            System.out.println("Load library failed!");
        }
    }
    public native static boolean InitCrypt(int nCryptType,String strKey,int nKeyLen);
    public native static String Encrypt(String strEnc,int nEnc,boolean bBase64Encode);
    public native static String Decrypt(String strDec,int nDec,boolean bBase64Decode);
    public native static void   ReleaseCrypt();    /**
     * @param args the command line arguments
     */    public static void main(String[] args) {        try
        {
            String strKey = "testshshtestshsh";            if (!CryptDemo.InitCrypt(0,strKey,strKey.length()))
                System.out.println("采用BlowFish算法初始化加密库失败!");
//            if ((args[0].isEmpty()) || (args[0] == ""))
//                System.out.println("请在命令行输入有效加密明文!");
/*
            String strSrc = args[0];
            String  strEncrypted = CryptDemo.Encrypt(strSrc,strSrc.length(),true);
            System.out.println("加密编码后字串:\n" + strEncrypted);
*/
            System.out.println("Secret:\n" + args[0]);
            String strPlain = CryptDemo.Decrypt(args[0],args[0].length(),true);
            System.out.println("Plain:\n" + strPlain);            CryptDemo.ReleaseCrypt();        }catch(Exception e)
        {
            e.printStackTrace();
        }
    }}
就在执行到             System.loadLibrary("csscrypt");时抛出这个异常,真郁闷啊,我在dll里的cpp文件中都已经实现了这几个方法了,链接时也已经把必要的o文件连接到so里面了,很急,高人帮我看看,分不是问题!

解决方案 »

  1.   

    我贴下我的编译命令和参数,也可能与这个有关啊
    cc -shared -o csscrypt.so BFCrypt.o CipherServer.o Blowfish.o cpkernel.o AES.o arcfour.o cast.o CRC32.o LZSS.o MD5.o Serpent.o SHA1.o SHA512.o Support.o TMS.o TripleDES.o Twofish.o Yarrow.o用上面这个命令参数,生成后调用就弹出我上面所的未定义符号异常gcc BFCrypt.cpp CipherServer.c Blowfish.c cpkernel.c AES.c arcfour.c cast.c CRC32.c LZSS.c MD5.c Serpent.c SHA1.c SHA512.c Support.c TMS.c TripleDES.c Twofish.c Yarrow.c -fPIC -shared -o libcsscrypt.so用这个命令行参数编译,调用时就显示下面的异常了,未定义symbol变为 __gxx_personality_v0了 ,不知道这个是不是和我
    编译参数有关啊? 我是同一套代码在windows时调用是完全没有问题的... - -! 
    急 啊
      

  2.   

    http://blog.csdn.net/Mr_Von/archive/2008/09/04/2878508.aspx
    LZ可以参考一下。
      

  3.   

    /usr/lib/jvm/java-6-sun-1.6.0.00/jre/lib/i386/libcsscrypt.so你应该放在上面的这个目录,你仔细看看吧。
      

  4.   

    真是感谢各位啦,谢谢老紫竹 :) 问题已经解决了。。是编译有问题,我用g++ 编译就好了,可能是有个cpp文件,gcc虽然能编译,但是生成的so文件格式有些问题,jni找不到接口,用g++就完全ok了,呵呵,我也是第一回用jni才犯了这个错..
      

  5.   

    呵呵。看来我要走的中还很长啊。我现在只明白有JNI这个理念,但还没用过。呵呵。听说要成为JAVA高手,要用二年学C/C++,三个月学JAVA,再剩下的时间设计方面和API的争对性学习了。