Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
470 views
in Technique[技术] by (71.8m points)

header - SWIG JNI Interface with DLL and declarations only

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...