chuanyueniwo 2018-11-22 06:06 采纳率: 0%
浏览 1606
已结题

Windows Mono C#调用C++ DLL DllNotFoundException 问题

我在windows7 环境下安装了最新版本的mono,运行了一些helloworld程序正常运行。
问题:我有一个C#项目,C#调用了C++的一个动态库,如果我用VS2008运行C#或者直接运行编译出的exe程序,都能正常调用C++dll, 但是我如果用mono 运行 exe程序就会报动态库找不到,System.DllNotFoundException。dll库就是求和功能,贴上 C++dll源码:sum.h

 #pragma once 
extern "C" _declspec(dllexport) int _stdcall sum(int a ,int b);

sum.cpp

 #include "Sum.h"
int _stdcall sum(int a,int b)
{
    return a + b;
}

C#工程源码:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace TestCppDLL
{
    class Program
    {
        [DllImport("GetSum", EntryPoint = "sum", CallingConvention = CallingConvention.StdCall)]
        public extern static int sum(int a, int b);
        static void Main(string[] args)
        {
             int num = sum(1,2);
            System.Console.WriteLine(num);
            System.Console.ReadLine();
        }
    }
}

自己搜索了一下:说是要在mono 的config中指定 dll 于是配置Mono安装目录下/etc/mono
/config文件:

 <dllmap dll="GetSum.dll" target="C:/path/GetSum.dll"/>

运行还是同样的错误。我又单独配置了GetSum.dll.config 内容:

 <configuration>
    <dllmap dll="GetSum.dll" target="C:/path/GetSum.dll" />
</configuration>

依然是同样的错误!!!!!

哪位大神给解答下啊。。。。。

  • 写回答

2条回答

  • threenewbee 2018-11-22 06:09
    关注

    mono没有用过,比较怀疑你的程序是不是编译成64bit的了,所以无法找到32bit的dll

    还有,难道你在linux下运行?那没法用dll,linux下的动态库是so,要用gcc的编译器、链接器。你google下

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题