【发布时间】:2013-01-27 20:09:51
【问题描述】:
我刚刚下载了 libtesseract302,并喜欢通过 JNA 使用它从 java 应用程序中导出的一些函数。我的测试应用程序已成功加载该库,但未找到这些函数。我的简单 tesseract api 界面如下所示: {{{ 公共接口 TessAPI 扩展库 {
public static final TessAPI INSTANCE = (TessAPI) Native.loadLibrary("libtesseract302", TessAPI.class);
int Init(String datapath, String language);
public static class TessBaseAPI extends PointerType {
public TessBaseAPI(Pointer address) {
super(address);
}
public TessBaseAPI() {
super();
}
};
}
}}}
当我尝试使用此代码时,我得到了这个异常:
java.lang.UnsatisfiedLinkError: Error looking up function 'Init': A megadott eljárás nem található.
at com.sun.jna.Function.<init>(Function.java:179)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:350)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:330)
at com.sun.jna.Library$Handler.invoke(Library.java:203)
at $Proxy5.Init(Unknown Source)
at net.docca.backend.ocr.TesseractApplication.run(TesseractApplication.java:53)
at net.docca.backend.ocr.TesseractApplicationTest.testRun(TesseractApplicationTest.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:128)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)
at org.testng.TestNG.run(TestNG.java:1036)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
我认为这是因为dll中导出的函数有奇怪的名字,例如:?Init@TessBaseAPI@tesseract@@QEAAHPEBD0@Z
我的问题是:我应该如何在上述代码中调用我的方法,以便将它们映射到正确的 dll 函数?
【问题讨论】:
-
这是一个 C++ 错位名称。 JNAerator 可以促进 de-mangling,因此您可以调用静态 C++ 方法,但通常 JNA 不直接支持在 C++ 对象上实例化或调用方法。如果您只关心调用全局/静态函数,请使用
extern "C"将它们导出为未修饰。