public class NativeLibrary extends Object
getProcess()
).
Library Search Paths A search for a given library will scan the following locations:
jna.library.path
User-customizable path
jna.platform.library.path
Platform-specific paths
~/Library/Frameworks
,
/Library/Frameworks
, and
/System/Library/Frameworks
will be searched for a framework
with a name corresponding to that requested.
Modifier and Type | Field and Description |
---|---|
(package private) int |
callFlags |
(package private) Map |
options |
Modifier and Type | Method and Description |
---|---|
static void |
addSearchPath(String libraryName,
String path)
Add a path to search for the specified library, ahead of any system
paths.
|
void |
dispose()
Close the native library we're mapped to.
|
(package private) static void |
disposeAll()
Close all open native libraries.
|
protected void |
finalize()
Close the library when it is no longer referenced.
|
File |
getFile()
Returns the file on disk corresponding to this NativeLibrary instance.
|
Function |
getFunction(String functionName)
Create a new
Function that is linked with a native
function that follows the NativeLibrary's calling convention. |
Function |
getFunction(String functionName,
int callFlags)
Create a new @{link Function} that is linked with a native
function that follows a given calling flags.
|
(package private) Function |
getFunction(String name,
Method method)
Create a new
Function that is linked with a native
function that follows the NativeLibrary's calling convention. |
Pointer |
getGlobalVariableAddress(String symbolName)
Look up the given global variable within this library.
|
static NativeLibrary |
getInstance(String libraryName)
Returns an instance of NativeLibrary for the specified name.
|
static NativeLibrary |
getInstance(String libraryName,
Map options)
Returns an instance of NativeLibrary for the specified name.
|
String |
getName()
Returns the simple name of this library.
|
Map |
getOptions()
Returns this native library instance's options.
|
static NativeLibrary |
getProcess()
Returns an instance of NativeLibrary which refers to the current
process.
|
static NativeLibrary |
getProcess(Map options)
Returns an instance of NativeLibrary which refers to the current
process.
|
(package private) long |
getSymbolAddress(String name)
Used by the Function class to locate a symbol
|
(package private) static String |
matchFramework(String libraryName)
Look for a matching framework (OSX)
|
(package private) static String |
matchLibrary(String libName,
List searchPath)
matchLibrary() is very Linux specific.
|
(package private) static double |
parseVersion(String ver) |
String |
toString() |
final int callFlags
final Map options
public static final NativeLibrary getInstance(String libraryName)
More than one name may map to the same NativeLibrary instance; only a single instance will be provided for any given unique file path.
libraryName
- The library name to load.
This can be short form (e.g. "c"),
an explicit version (e.g. "libc.so.6"), or
the full path to the library (e.g. "/lib/libc.so.6").public static final NativeLibrary getInstance(String libraryName, Map options)
More than one name may map to the same NativeLibrary instance; only a single instance will be provided for any given unique file path.
libraryName
- The library name to load.
This can be short form (e.g. "c"),
an explicit version (e.g. "libc.so.6" or
"QuickTime.framework/Versions/Current/QuickTime"), or
the full (absolute) path to the library (e.g. "/lib/libc.so.6").options
- native library options for the given library (see Library
).public static final NativeLibrary getProcess()
public static final NativeLibrary getProcess(Map options)
public static final void addSearchPath(String libraryName, String path)
libraryName
- The name of the library to use the path forpath
- The path to use when trying to load the librarypublic Function getFunction(String functionName)
Function
that is linked with a native
function that follows the NativeLibrary's calling convention.
The allocated instance represents a pointer to the named native function from the library.
functionName
- Name of the native function to be linked withUnsatisfiedLinkError
- if the function is not foundFunction getFunction(String name, Method method)
Function
that is linked with a native
function that follows the NativeLibrary's calling convention.
The allocated instance represents a pointer to the named native function from the library.
name
- Name of the native function to be linked withmethod
- Method to which the native function is to be mappedUnsatisfiedLinkError
- if the function is not foundpublic Function getFunction(String functionName, int callFlags)
functionName
- Name of the native function to be linked withcallFlags
- Flags affecting the function invocationUnsatisfiedLinkError
- if the function is not foundpublic Map getOptions()
public Pointer getGlobalVariableAddress(String symbolName)
symbolName
- UnsatisfiedLinkError
- if the symbol is not foundlong getSymbolAddress(String name)
UnsatisfiedLinkError
- if the symbol can't be foundpublic String getName()
public File getFile()
protected void finalize()
static void disposeAll()
public void dispose()
static String matchLibrary(String libName, List searchPath)
static double parseVersion(String ver)