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

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

问题描述

我有我想通过JNI
访问的本机函数声明,并且我拥有所有类声明的DLL。



我没有完整的头文件及其依赖关系,但我确实有DLL
,其中包含所有信息。



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



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

解决方案

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



它需要包含有关您关心的功能的信息(不一定是全部)和您关心的类型(不一定是全部他们,但你需要知道他们的名字为每个功能)。



与你一样,你可以构建一个模块文件。你可以猜测/推断出一些信息,具体取决于它是C ++还是C - 如果它是C ++,那么这个被破坏的名字会告诉你最需要知道的输入,而不是返回类型。






作为一个例子我编译:

  class foo {}; 

foo * make_foo(){return new foo; }

void eat_foo(foo *){}

void frobinate_two_foos(foo *,foo *){}

作为DLL使用:

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

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

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

有趣的是:

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

所以我可以推断一个SWIG模块包装可能如下所示:

 %module reverse 

class foo; //没有更多的知道

foo * make_foo();

void frobinate_two_foos(foo *,foo *); //返回类型猜测

//忽略eat_foo,我根本不知道该做什么!

您仍然需要构造足够的头以允许生成的包装器编译。 / p>

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.

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

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