c++ - 系统.DllNotFoundException : Unable to load DLL with dotnet core

标签 c++ c linux .net-core

我的任务是在 Linux 上从 dotnet core 调用 openzwave,但我在 dotnet core 加载我的 c++ 库时遇到了问题。基本上任何时候我接触 openzwave 库我都会得到一个 dll not found 异常。 这是我的 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 的一个版本

#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 和这个库都在预期的路径上。 N.B 在 Windows 上编译时这一切都有效。 openZwave on github

最佳答案

您是否尝试过在 C 程序中使用您的库?也许 OpenZWave 有一些在 linux 上缺少的依赖项......

关于c++ - 系统.DllNotFoundException : Unable to load DLL with dotnet core,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41871068/

相关文章:

c - 是否已经定义了 gstreamer 元数据的标准模板?

c - 我动态分配的结构体指针数组有什么问题?

c - 从 STM32F0 和 zlib 匹配 CRC32

linux - 查找正则表达式匹配条件

c++ - 如何使用 C/C++ 以编程方式检查 Windows 中的系统文件夹?

c++ - 生成给定字符串的条件排列

c# - 在 C# 中直接从 char int 转换为 char

c++ - 尝试设置 cv::Mat 的像素值时抛出段错误

c - 一元运算符歧义

android - 直接在移动网络上访问android应用程序端口