From 947aac986c6ae53b6350d21524172ba88ef1b413 Mon Sep 17 00:00:00 2001 From: grbd Date: Tue, 12 Jan 2016 22:37:29 +0000 Subject: [PATCH] Added the ability to search the machine Path or a specified path for the library file as part of ResolveSymbol --- src/Runtime/SymbolResolver.cs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Runtime/SymbolResolver.cs b/src/Runtime/SymbolResolver.cs index 9833c849..024e9eb3 100644 --- a/src/Runtime/SymbolResolver.cs +++ b/src/Runtime/SymbolResolver.cs @@ -57,9 +57,33 @@ namespace CppSharp public static IntPtr LoadImage (ref string name) { + var pathvalues = Environment.GetEnvironmentVariable("PATH"); + foreach (var format in formats) { - var attempted = System.IO.Path.Combine(Environment.CurrentDirectory, string.Format (format, name)); + // Search the Current or specified directory for the library + string filename = string.Format(format, name); + string attempted = System.IO.Path.Combine(Environment.CurrentDirectory, filename); + if (!System.IO.File.Exists(attempted)) + { + // Search the Path directories for the library + if (pathvalues == null) + continue; + + foreach (var path in pathvalues.Split(System.IO.Path.PathSeparator)) + { + var fullPath = System.IO.Path.Combine(path, filename); + if (System.IO.File.Exists(fullPath)) + { + attempted = fullPath; + break; + } + + } + } + if (!System.IO.File.Exists(attempted)) + continue; + var ptr = loadImage (attempted); if (ptr == IntPtr.Zero)