jayunit100
jayunit100

Reputation: 17648

Finding exposed methods in native libraries to access over JNA / JNI?

Hi : I wanted to use JNA to access some functions in a native library.

1) How can i introspect the native library files (.so files, for example) to see what methods are available ?

2) Is there a one-one mapping between the methods accessible in .so files and the C code built to compile those files?

3) Is JNA gauranteed to work in all cases where the only java/native interop involves calling native libraries from Java (I assume this is the classic use case for JNA) -- or is JNI sometimes required instead?

Upvotes: 1

Views: 2076

Answers (1)

technomage
technomage

Reputation: 10069

1) depends.exe on windows, objdump, nm, et al. on *nix variants.

2) Most shared libraries are designed for C-style linkage. This generally means that you can look up addresses corresponding to symbols in the library, but the type (variable, constant, or function) and signature information (for functions) is not usually embedded in the library.

3) JNA uses a very few generalized JNI operations to perform all its magic: open shared libraries, look up symbols, read/write memory, call functions. There are very few situations where you would have to use JNI over JNA, at least when dealing with libraries with C linkage.

Upvotes: 4

Related Questions