System.DllNotFoundException:无法与dotnet的核心加载DLL(Syst

2019-09-27 01:33发布

我一直在负责调用从DOTNET核心openzwave在Linux上,我有我的装载C ++库DOTNET核心问题。 基本上任何时候我碰openzwave库我得到未发现异常的DLL。 这里是我的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}");

            }
        }
    }

继承人版本其运作。所以

#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这11b是预期的路径上。 NB时,这个窗口的所有作品汇编。 openZwave在github

Answer 1:

你有没有试过用一个C程序中你的lib? 也许这OpenZWave有一些依赖关系丢失在Linux上...



Answer 2:

解决它!。 我做了,呼吁其向我指出的问题。所以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;
}

克++ -o主要的main.cpp -ldl
。/主要

你好,世界!

无法加载LIB

libopenzwave.so.1.4:无法打开共享对象文件:没有这样的文件或目录

一个快速的符号链接后,它的所有作品:)



文章来源: System.DllNotFoundException: Unable to load DLL with dotnet core