IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
IKVM.Runtime.NativeLibrary Class Reference

Provides methods to load libraries from standard .NET search locations. This class is not used to load native libraries for JNI. On platforms that have native NativeLibrary support, that support is used. On other platforms, libikvm is used to invoke the platform loader. More...

Static Public Member Functions

static string MapLibraryName (string name)
 Returns a version of the library name with the OS specific prefix and suffix.
 
static NativeLibraryHandle Load (string nameOrPath)
 Loads the given library in a platform dependent manner.
 

Detailed Description

Provides methods to load libraries from standard .NET search locations. This class is not used to load native libraries for JNI. On platforms that have native NativeLibrary support, that support is used. On other platforms, libikvm is used to invoke the platform loader.

Definition at line 15 of file NativeLibrary.cs.

Member Function Documentation

◆ Load()

static NativeLibraryHandle IKVM.Runtime.NativeLibrary.Load ( string nameOrPath)
static

Loads the given library in a platform dependent manner.

Parameters
nameOrPath
Returns

Definition at line 66 of file NativeLibrary.cs.

67 {
68 if (Path.IsPathRooted(nameOrPath))
69 return LoadImpl(nameOrPath);
70
71 // give native loader a chance to load the library
72 if (LoadImpl(nameOrPath) is NativeLibraryHandle h1)
73 return h1;
74
75 // start looking at assembly path, or path given by environmental variable
76 var asml = typeof(NativeLibrary).Assembly.Location is string s && !string.IsNullOrEmpty(s) ? Path.GetDirectoryName(s) : null;
77 var root = Environment.GetEnvironmentVariable("IKVM_LIBRARY_PATH") ?? asml;
78
79 // assembly possible loaded in memory: we have no available search path
80 if (string.IsNullOrEmpty(root))
81 return null;
82
83 // check in root directory
84 if (Path.Combine(root, MapLibraryName(nameOrPath)) is string lib1)
85 if (File.Exists(lib1) && LoadImpl(lib1) is NativeLibraryHandle h2)
86 return h2;
87
88 // scan supported RIDs for current platform
89 foreach (var rid in RuntimeUtil.SupportedRuntimeIdentifiers)
90 if (Path.Combine(root, "runtimes", rid, "native", MapLibraryName(nameOrPath)) is string lib2)
91 if (File.Exists(lib2) && LoadImpl(lib2) is NativeLibraryHandle h3)
92 return h3;
93
94 return null;
95 }
static string MapLibraryName(string name)
Returns a version of the library name with the OS specific prefix and suffix.

◆ MapLibraryName()

static string IKVM.Runtime.NativeLibrary.MapLibraryName ( string name)
static

Returns a version of the library name with the OS specific prefix and suffix.

Parameters
name
Returns

Definition at line 29 of file NativeLibrary.cs.

30 {
31 if (name == null)
32 return null;
33 if (Path.HasExtension(name))
34 return name;
35
36 if (RuntimeUtil.IsWindows)
37 return name + ".dll";
38 else if (RuntimeUtil.IsOSX)
39 return "lib" + name + ".dylib";
40 else
41 return "lib" + name + ".so";
42 }

The documentation for this class was generated from the following file: