Browse Source

fix: cannot load library under some conditions.

tags/v0.8.0
Yaohui Liu 2 years ago
parent
commit
bbbfbd20b5
No known key found for this signature in database GPG Key ID: E86D01E1809BD23E
1 changed files with 28 additions and 4 deletions
  1. +28
    -4
      LLama/Native/NativeApi.cs

+ 28
- 4
LLama/Native/NativeApi.cs View File

@@ -262,19 +262,43 @@ namespace LLama.Native

var libraryTryLoadOrder = GetLibraryTryOrder(configuration);

foreach(var libraryPath in libraryTryLoadOrder)
string[] possiblePathPrefix = new string[] {
System.AppDomain.CurrentDomain.BaseDirectory,
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) ?? ""
};

var tryFindPath = (string filename) =>
{
int i = 0;
while (!File.Exists(filename))
{
if (i < possiblePathPrefix.Length)
{
filename = Path.Combine(possiblePathPrefix[i], filename);
i++;
}
else
{
break;
}
}
return filename;
};

foreach (var libraryPath in libraryTryLoadOrder)
{
var result = TryLoad(libraryPath, true);
var fullPath = tryFindPath(libraryPath);
var result = TryLoad(fullPath, true);
if(result is not null && result != IntPtr.Zero)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"[Native Library] {libraryPath} is loaded.");
Console.WriteLine($"[Native Library] {fullPath} is loaded.");
Console.ResetColor();
return result ?? IntPtr.Zero;
}
else
{
Console.WriteLine($"Tried to load {libraryPath}");
Console.WriteLine($"Tried to load {fullPath}");
}
}



Loading…
Cancel
Save