System.DllNotFoundException:无法使用 dotnet core 加载 DLL
System.DllNotFoundException: Unable to load DLL with dotnet core
我的任务是从Linux上的dotnet core调用openzwave,我在加载c ++库时遇到了dotnet core的问题。基本上,每当我触摸openzwave库时,我都会得到一个dll未找到异常。这是我的程序.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 的一个版本,它有效
#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和这个lib都走在预期的道路上。注意,当在Windows上编译时,这一切都有效。openZwave on github
您是否尝试过在 C 程序中使用您的库?也许 OpenZWave 有一些在 Linux 上缺少的依赖项......
解决了!.我做了一个叫做.so的c ++程序,它指出了我的问题:)
#include <iostream>
#include <dlfcn.h>
typedef int (*moo)();
int main()
{
std::cout << "Hello World!" << std::endl;
void* myso = dlopen("/home/mark/open-zwave/.lib/MinOZW.so", RTLD_NOW );
// void* myso = dlopen("/home/mark/open-zwave/libopenzwave.so", RTLD_NOW);
if (!myso){
std::cout << "Failed to load lib " << dlerror() << std::endl;
return 1;
}
// moo func =(moo) dlsym(myso, "Free");
// func();
dlclose(myso);
return 0;
}
g++ -o main main.cpp -ldl
。/主要世界您好!
无法加载库
libopenzwave.so.1.4:无法打开共享对象文件:没有这样的文件或目录
稍后一个快速符号链接,一切都:)
相关文章:
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- C++包含来自 #include "DevEngine/Core.h" 的错误
- CoreCLR 中的检测探查器 - 将帮助程序程序集加载到 dotnet 进程的方法
- 是否可以在Linux上使用.Net Core 3.1创建C++/CLI代码的C#DLL
- 构建 TensorFlow r1.14 C++文件时缺少文件"tensorflow/core/framework/types.pb.h"
- 不要使用静态强制转换进行算术转换(cpp-core-guidelines)
- C++ DLL(不是 CLI)是否可以调用 .NET Core 3.0 委托?
- C++/CLI targetting .NET Core 3.1
- 同时使用Opengl CORE函数以及Comptability Profile - GLFW
- 是否有可能构建面向Linux和Windows的.Net Core C++ / CLI应用程序?
- 为什么此代码中显示"*** stack smashing detected ***: <unknown> terminated Aborted (core dumped) "错误?
- 避免在使用WinAPI(Windows Core Audio)时无效的指针
- 在.NET Core 3.1中运行托管C++/CLI程序集时,映像格式错误
- 以C++为目标的Windows Server Core
- 无法将 c# .Net Core 3.0 与 directx 9.0 依赖项链接
- 如何从.NET Core调用cygwin编译的C++
- 在.NET Core中是否有与DllImport等效的Linux?
- 如何修复访问动态数组中结构中的字符串变量时"segmentation fault (core dumped)"错误
- 将结构数组从 C#(.NET Core) 传递到 C++(unamnaged)
- System.DllNotFoundException:无法使用 dotnet core 加载 DLL