System.DllNotFoundException:无法使用 dotnet 核心加载 DLL [英] System.DllNotFoundException: Unable to load DLL with dotnet core
问题描述
我的任务是从 linux 上的 dotnet 核心调用 openzwave,但我在 dotnet 核心加载我的 C++ 库时遇到了问题.基本上每当我接触 openzwave 库时,我都会收到一个 dll not found 异常.这是我的 program.cs
I've been tasked with calling openzwave from dotnet core on linux and i'm having issues with dotnet core loading my c++ library. Essentially any time i touch the openzwave library I get a dll not found exception. here's my program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace MinOZWDotNet
{
public class Program
{
[DllImport("MinOZW")]
public static extern int Init();
[DllImport("MinOZW")]
public static extern int Free();
public static void Main(string[] args)
{
Console.WriteLine("Calling Init");
var val= Init();
Console.WriteLine($"retval= {val}");
while (true)
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey();
if (key.Key == ConsoleKey.Escape)
{
Console.WriteLine("Exit");
break;
}
}
}
Console.WriteLine("Calling Free");
val = Free();
Console.WriteLine($"retval = {val}");
}
}
}
这是 .so 的一个版本
heres a version of the .so which works
#ifdef __GNUC__
#define EXPORT extern "C"
#define CC
#else
#define EXPORT extern "C" __declspec (dllexport)
#define CC __stdcall
#endif
#ifdef __GNUC__
#include <stdlib.h>
#include <unistd.h>
#include "Defs.h"
#else
#include "Windows.h"
#endif
EXPORT int CC Init() {
return 0;
}
EXPORT int CC Free() {
return 0;
}
这是给我错误的版本
#ifdef __GNUC__
#define EXPORT extern "C"
#define CC
#else
#define EXPORT extern "C" __declspec (dllexport)
#define CC __stdcall
#endif
#ifdef __GNUC__
#include <stdlib.h>
#include <unistd.h>
#include "Defs.h"
#else
#include "Windows.h"
#endif
#include "Options.h"
#include "Manager.h"
#include "Driver.h"
#include "Node.h"
#include "Group.h"
#include "Notification.h"
#include "value_classes/ValueStore.h"
#include "value_classes/Value.h"
#include "value_classes/ValueBool.h"
#include "platform/Log.h"
using namespace OpenZWave;
EXPORT int CC Init() {
Manager::Create();
return 0;
}
EXPORT int CC Free() {
Manager::Destroy();
return 0;
}
openzwave 和这个库都在预期的路径上.注意,在 Windows 上编译时,这一切正常.github上的openZwave
both openzwave and this lib are on the expected path. N.B when compiled on windows this all works. openZwave on github
推荐答案
您是否尝试过在 C 程序中使用您的 lib?也许 OpenZWave 有一些在 linux 上缺少的依赖项...
Have you tried to use your lib inside a C program? Maybe that OpenZWave has some dependencies that are missing on linux...
这篇关于System.DllNotFoundException:无法使用 dotnet 核心加载 DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!