【发布时间】:2018-10-19 15:19:03
【问题描述】:
我有一个用 C# 编写的 .NET 项目,它依赖于 CoolProp 库(可在此处获取 https://github.com/CoolProp/CoolProp)。它使用 PInvoke 调用 CoolProp 函数。
不幸的是,我必须在 linux 环境中运行这个程序(准确地说是 AWS lambda env https://docs.aws.amazon.com/en_us/lambda/latest/dg/current-supported-versions.html)。
现在,我想在装有 Ubuntu 操作系统的 PC 上使用 .NET core(命令 dotnet run)执行它,但我总是收到以下错误:
Unhandled Exception: System.DllNotFoundException:
Unable to load shared library 'libCoolProp.so' or one of its dependencies.
In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibCoolProp.so.so: cannot open shared object file: No such file or directory
at Test1.Program.PropsSI(String Output, String Name1, Double Prop1, String Name2, Double Prop2, String Ref)
at Test1.Program.Main(String[] args) in /home/user/Desktop/TestDllInUbuntu/Test1/Program.cs:line 23
测试程序是:
using System;
using System.Runtime.InteropServices;
namespace Test1
{
class Program
{
[DllImport("libCoolProp.so")]
private static extern double PropsSI(string Output, string Name1, double Prop1, string Name2, double Prop2, string Ref);
static void Main(string[] args)
{
double propsRes = PropsSI("H", "T", 300.0, "Q", 0.0, "R410A");
Console.WriteLine(propsRes);
}
}
}
Program.cs 与libCoolProp.so 位于同一文件夹中。
注意事项:
- 使用 .Net Core 编译和执行 Windows 10 中的同一程序,其
libCoolProp.dll工作正常。 - 在 Ubuntu 18 中使用 Mono Runtime 编译和执行的相同程序可以工作。
如何解决 CoolProp lib 与 .Net Core 运行时的兼容性问题?
【问题讨论】:
标签: c# .net-core shared-libraries pinvoke c#-native-library