设置非托管DLL加载目录

时间:2014-02-17 10:13:22

标签: c# linux environment-variables dllimport

我需要从特定目录加载库。我想暂时将此文件夹添加到搜索路径中,而不是使用LoadLibrary(Windows)或dlopen(Linux)等特定功能。

所以我有:

public static void AddOrUpdateDllPath(string dllDirectory)
    {
        dllDirectory = dllDirectory.NormalizePathDelimiters("\\");

        var path = "";
        switch (RunningPlatform)
        { 
            case OperatingSystem.Windows:
                path = "PATH";
                Environment.SetEnvironmentVariable(path, Environment.GetEnvironmentVariable(path) + ";" + dllDirectory);
                break;
            case OperatingSystem.MacOS:
                path = "LD_LIBRARY_PATH";
                throw new NotImplementedException("How to change " + path);
                break;
            case OperatingSystem.Linux:
                path = "DYLD_FRAMEWORK_PATH";
                throw new NotImplementedException("How to change " + path);
                break;
        }
    }

我不知道如何为Linux和MaxOS添加路径变量?

0 个答案:

没有答案