Compute.Bindings.IntelMKL by Allister Beharry

<PackageReference Include="Compute.Bindings.IntelMKL" Version="0.1.5" />

 SymbolResolver

public static class SymbolResolver
using System; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Runtime.InteropServices; namespace CppSharp { public static class SymbolResolver { private static readonly string[] formats; private static readonly Func<string, IntPtr> loadImage; private static readonly Func<IntPtr, string, IntPtr> resolveSymbol; private const int RTLD_LAZY = 1; static SymbolResolver() { PlatformID platform = Environment.OSVersion.Platform; if (platform == PlatformID.Unix || platform == PlatformID.MacOSX) { loadImage = dlopen; resolveSymbol = dlsym; formats = new string[6] { "{0}", "{0}.so", "{0}.dylib", "lib{0}.so", "lib{0}.dylib", "{0}.bundle" }; } else { loadImage = LoadLibrary; resolveSymbol = GetProcAddress; formats = new string[2] { "{0}", "{0}.dll" }; } } public static IntPtr LoadImage(ref string name) { string environmentVariable = Environment.GetEnvironmentVariable("PATH"); List<string> list = new List<string>((environmentVariable == null) ? new string[0] : environmentVariable.Split(new char[1] { Path.PathSeparator })); list.Insert(0, Directory.GetCurrentDirectory()); list.Insert(0, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); string[] array = formats; for (int i = 0; i < array.Length; i++) { string path = string.Format(array[i], name); string text = null; foreach (string item in list) { string text2 = Path.Combine(item, path); if (File.Exists(text2)) { text = text2; break; } } if (File.Exists(text)) { IntPtr intPtr = loadImage(text); if (!(intPtr == IntPtr.Zero)) { name = text; return intPtr; } } } return IntPtr.Zero; } public static IntPtr ResolveSymbol(string name, string symbol) { return ResolveSymbol(LoadImage(ref name), symbol); } public static IntPtr ResolveSymbol(IntPtr image, string symbol) { if (image != IntPtr.Zero) return resolveSymbol(image, symbol); return IntPtr.Zero; } private static IntPtr dlopen(string path) { return dlopen(path, 1); } [DllImport("dl", CharSet = CharSet.Ansi)] private static extern IntPtr dlopen(string path, int flags); [DllImport("dl", CharSet = CharSet.Ansi)] private static extern IntPtr dlsym(IntPtr handle, string symbol); [DllImport("kernel32", SetLastError = true)] private static extern IntPtr LoadLibrary(string lpFileName); [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)] private static extern IntPtr GetProcAddress(IntPtr hModule, string procName); } }