System.DllNotFoundException:无法使用dotnet核心加载DLL [英] System.DllNotFoundException: Unable to load DLL with dotnet core

查看:275
本文介绍了System.DllNotFoundException:无法使用dotnet核心加载DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是在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版本

#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上编译时,N.B可以正常工作. 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆