Java(JNA) - 在DLL(C ++)库中找不到函数 [英] Java (JNA) - can't find function in DLL (C++) library

查看:3437
本文介绍了Java(JNA) - 在DLL(C ++)库中找不到函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java中是新的,在google和stackoverflow中搜索了这个问题,发现了一些帖子,但仍然无法理解。



我想使用DLL来自Java的libary(C ++)方法。我为此目的使用JNA。 JNA找到我的库,但找不到我的方法:
线程main中的异常java.lang.UnsatisfiedLinkError:查找函数LoadCurrentData时出错:指定的过程无法找到



我的代码:

 包javaapplication1; 

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
import com.sun.jna.Pointer;

public class JavaApplication1 {

public interface LibPro extends Library {
LibPro INSTANCE =(LibPro)Native.loadLibrary(
(Platform.isWindows() ?LibPro:LibProLinuxPort),LibPro.class);

public short LoadCurrentData();
}

public static void main(String [] args){
LibPro sdll = LibPro.INSTANCE;
sdll.LoadCurrentData(); //调用void函数
}
}

我查看了我的DLL与Depency Walker工具,看到我的函数名称有前缀和后缀 - 它看起来像 _LoadCurrentData @ 0



谢谢为了回应!



PS我找到了一个很好的例子,它的作品有 http://tutortutor.ca/cgi-bin/ makepage.cgi?/ articles / rjna (清单6)。

解决方案

我会说你需要应用正确的名称映射器,因为您注意到函数名称被破坏,您需要注册 CallMapper ,这将实现与编译器相同的调整。



这是一个可爱的条目


使用转储实用程序检查导出的函数的名称,以确保它们匹配(nm on linux,取决于Windows)。在Windows上,如果函数的后缀为@NN,则在初始化库接口时需要传递StdCallFunctionMapper作为选项。一般来说,您可以使用函数映射器(FunctionMapper)来更改查找方法的名称,或调用映射器(InvocationMapper),以便对方法调用进行更广泛的控制。




这可能是一个可能的问题:使用StdCallFunctionMapper重命名JNA中的DLL函数


I am new in Java, searched for this question in google and stackoverflow, found some posts, but still I can't understand.

I want to use DLL libary (C++) methods from Java. I use JNA for this purpose. JNA found my library but it can't find my method: Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'LoadCurrentData': The specified procedure could not be found.

My code:

package javaapplication1;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
import com.sun.jna.Pointer;

public class JavaApplication1 {

    public interface LibPro extends Library {
        LibPro INSTANCE = (LibPro) Native.loadLibrary(
            (Platform.isWindows() ? "LibPro" : "LibProLinuxPort"), LibPro.class);

        public  short LoadCurrentData();
    }

    public static void main(String[] args) {
      LibPro sdll = LibPro.INSTANCE;
      sdll.LoadCurrentData();  // call of void function
    }
 }

I looked in my DLL with Depency Walker Tool and saw that my function name has prefix and suffix - it looks like _LoadCurrentData@0

Thanks for response!

P.S. I found good example which works http://tutortutor.ca/cgi-bin/makepage.cgi?/articles/rjna (Listing 6).

解决方案

I'd say that you need to apply correct name mapper, as you noticed function name got mangled, you need to register CallMapper that will implement the same mangling as your compiler.

Here is a revelant entry from JNA homepage:

Use a dump utility to examine the names of your exported functions to make sure they match (nm on linux, depends on Windows). On Windows, if the functions have a suffix of the form "@NN", you need to pass a StdCallFunctionMapper as an option when initializing your library interface. In general, you can use a function mapper (FunctionMapper) to change the name of the looked-up method, or an invocation mapper (InvocationMapper) for more extensive control over the method invocation.

Here is a possibly revelant question: renaming DLL functions in JNA using StdCallFunctionMapper

这篇关于Java(JNA) - 在DLL(C ++)库中找不到函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆