Skip to content

Commit ea7741e

Browse files
committed
Apparently Linux this days has only libdl.so.2
1 parent f72bbcb commit ea7741e

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

src/Providers.MKL/NativeProviderLoader.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static bool TryLoadDirect(string fileName)
322322
try
323323
{
324324
// If successful this will return a handle to the library
325-
libraryHandle = IsUnix ? UnixLoader.LoadLibrary(fileName) : WindowsLoader.LoadLibrary(fileName);
325+
libraryHandle = IsWindows ? WindowsLoader.LoadLibrary(fileName) : IsMac ? MacLoader.LoadLibrary(fileName) : LinuxLoader.LoadLibrary(fileName);
326326
}
327327
catch (Exception e)
328328
{
@@ -386,7 +386,7 @@ static bool TryLoadFile(string directory, string relativePath, string fileName)
386386
try
387387
{
388388
// If successful this will return a handle to the library
389-
libraryHandle = IsUnix ? UnixLoader.LoadLibrary(fullPath) : WindowsLoader.LoadLibrary(fullPath);
389+
libraryHandle = IsWindows ? WindowsLoader.LoadLibrary(fullPath) : IsMac ? MacLoader.LoadLibrary(fullPath) : LinuxLoader.LoadLibrary(fullPath);
390390
}
391391
catch (Exception e)
392392
{
@@ -428,7 +428,7 @@ public static IntPtr LoadLibrary(string fileName)
428428

429429
[SuppressUnmanagedCodeSecurity]
430430
[SecurityCritical]
431-
static class UnixLoader
431+
static class LinuxLoader
432432
{
433433
public static IntPtr LoadLibrary(string fileName)
434434
{
@@ -437,7 +437,22 @@ public static IntPtr LoadLibrary(string fileName)
437437

438438
const int RTLD_NOW = 2;
439439

440-
[DllImport("libdl", SetLastError = true)]
440+
[DllImport("libdl.so.2", SetLastError = true)]
441+
static extern IntPtr dlopen(String fileName, int flags);
442+
}
443+
444+
[SuppressUnmanagedCodeSecurity]
445+
[SecurityCritical]
446+
static class MacLoader
447+
{
448+
public static IntPtr LoadLibrary(string fileName)
449+
{
450+
return dlopen(fileName, RTLD_NOW);
451+
}
452+
453+
const int RTLD_NOW = 2;
454+
455+
[DllImport("libdl.dylib", SetLastError = true)]
441456
static extern IntPtr dlopen(String fileName, int flags);
442457
}
443458
#endif

0 commit comments

Comments
 (0)