我在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>
依然是同样的错误!!!!!
哪位大神给解答下啊。。。。。