仅带有 DLL 和声明的 SWIG JNI 接口 [英] SWIG JNI Interface with DLL and declarations only

查看:25
本文介绍了仅带有 DLL 和声明的 SWIG JNI 接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有想要通过 JNI 访问的本机函数声明并且我拥有包含所有类声明的 DLL.

我没有完整的头文件及其依赖项,但我有 DLL其中包含所有信息.

是否可以使用 SWIG 创建 JNI 接口只有 DLL 和函数声明?

另请参阅:SWIG CYGWIN DLL 链接这是一个非常相似的问题.

解决方案

你不能这样做,除非你能 从 DLL 中猜测足够的信息,以便能够重建(可能是部分的)头文件.

它需要包含有关您关心的函数(不必是全部)和您关心的类型(不必是全部,但您需要知道每个函数的名称)的信息).

这样您就可以正常构建模块文件了.您可以根据它是 C++ 还是 C 来猜测/推断其中的一些信息 - 如果是 C++,则损坏的名称将告诉您大部分您需要知道的输入信息,而不是返回类型.

<小时>

作为我编译的例子:

类 foo {};foo *make_foo() { return new foo;}无效吃_foo(foo*) {}无效 frobinate_two_foos(foo*,foo*) {}

作为 DLL 使用:

i58​​6-mingw32msvc-g++ -shared -Wall -Wextra original.cc -o test.dll

从中我可以看到 DLL 中的符号:

i58​​6-mingw32msvc-nm test.dll|i586-mingw32msvc-c++filt

有趣的是:

<上一页>6bec1286 T frobinate_two_foos(foo*, foo*)6bec1280 Teat_foo(foo*)6bec128c T make_foo()

所以我可以推断出包装这些的 SWIG 模块可能类似于:

%模块反转类 foo;//没有更多人知道foo *make_foo();无效 frobinate_two_foos(foo*,foo*);//猜测的返回类型//忽略了eat_foo,我根本不知道那是做什么的!

您仍然需要构建足够多的标头以允许生成的包装器编译.

I have the native function declarations I want to access via JNI and I have the DLL holding all class declarations.

I do not have the complete header file and its dependencies, but I do have the DLL which holds all the information.

Is it possible to create a JNI interface using SWIG with only having the DLL and the function declaration?

see also: SWIG CYGWIN DLL linking which is a very similar problem.

解决方案

You can't do this unless you can guess enough information from the DLL to be able to reconstruct a (possibly partial) header file.

It needs to contain information about the functions you care about (doesn't have to be all) and the types you care about (doesn't have to be all of them, but you need to know their names for every function).

With that you can construct a module file as normal. You can guess/infer some of that information depending on if it's C++ or C - if it's C++ the mangled name will tell you most of what you need to know for the inputs, but not the return types.


As an example I compiled:

class foo {};

foo *make_foo() { return new foo; }

void eat_foo(foo*) {}

void frobinate_two_foos(foo*,foo*) {}

as a DLL using:

i586-mingw32msvc-g++ -shared -Wall -Wextra original.cc -o test.dll

From that I can see the symbols in the DLL by doing:

i586-mingw32msvc-nm test.dll|i586-mingw32msvc-c++filt

The interesting ones are:

6bec1286 T frobinate_two_foos(foo*, foo*)
6bec1280 T eat_foo(foo*)
6bec128c T make_foo()

So I can infer that a SWIG module to wrap these might look something like:

%module reversed

class foo; // Nothing more known

foo *make_foo();

void frobinate_two_foos(foo*,foo*); // Return type guessed

// ignored eat_foo, I don't know what that does at all!

You'll still need to construct enough of a header to allow the generated wrapper to compile though.

这篇关于仅带有 DLL 和声明的 SWIG JNI 接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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