我正在嘗試在我最後一年的項目中使用一個包,名爲libfprint。這是一個開源的指紋識別器SDK。我正在做我的項目在Java中,所以我需要移植的libfprint功能。將JNI用於本地C包的UnsatisfiedLinkError libfprint
幸運的一擊打我,結果有人已經這樣做了。名爲jlibfprint的包是用於libfprint的JNI包裝。
所以我按照jlibfprint和libfprint中的說明進行設置。 libfprint或多或少的工作正常。至於jlibfprint,當我試圖運行我的示例程序,
Exception in thread "main" java.lang.UnsatisfiedLinkError: no JlibFprint_jni in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at JlibFprint.<clinit>(JlibFprint.java:28)
at SampleRun.main(SampleRun.java:30)
JlibFprint。(JlibFprint.java:28)
指的是
static {
System.loadLibrary("JlibFprint_jni");
}
所以現在我正在瀏覽項目屬性並轉到「本地庫位置」字段,並將其指向包含的目錄,該目錄名爲libJlibFprint_jni.so。
現在,當我運行程序時,我得到的錯誤是,
Exception in thread "main" java.lang.UnsatisfiedLinkError: JlibFprint.enroll_finger()LJlibFprint$fp_print_data;
at JlibFprint.enroll_finger(Native Method)
at SampleRun.main(SampleRun.java:36)
Enroll the first finger...
下面是示例Java文件
SampleRun.java
public class SampleRun {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
JlibFprint jlibfprint = new JlibFprint();
JlibFprint.fp_print_data pd1, pd2;
int matchValue;
try
{
System.out.println("Enroll the first finger...");
pd1 = jlibfprint.enroll_finger();
System.out.println("Compare the previous acquisition with the next one...");
pd2 = jlibfprint.enroll_finger();
matchValue = JlibFprint.img_compare_print_data(pd1, pd2);
System.out.println(matchValue);
if (matchValue > JlibFprint.BOZORTH_THRESHOLD)
{
System.out.println("[OK] The two fingerprints are compatible!");
}
else
{
System.out.println("[FAIL] The two fingerprints are not compatible!");
}
}
catch (JlibFprint.EnrollException e)
{
System.err.format("Enroll Exception [%d]\n", e.enroll_exception);
e.printStackTrace();
}
}
}
我使用Ubuntu 11.10與Eclipse Juno。
任何有這方面知識的人都會很有幫助!
更容易,你可以在Java定義接口對應功能libfprint簽名,避免使用JNA額外的JNI庫(http://github.com/twall/JNA)。 – technomage
嗯,如何快速/無痛地開始從頭開始?我是一個完全JNI newb,並且幾乎沒有C的知識。.. – TomSelleck
目前我必須使用Linux,因爲我的閱讀器只有驅動程序可用於Linux – TomSelleck