日期:2014-05-18  浏览次数:21305 次

c#在linux系统下调用c++的so文件
c++中的函数如下:DataBuffer* run(char* inputDataURL, char* runtimeFilePath)其中DataBuffer为结构。
由于要在linux系统下运行,所以c#中声明如下:[DllImport("test.so", EntryPoint = "run", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]  
public static extern IntPtr run([MarshalAs(UnmanagedType.LPArray)]byte[] uml, [MarshalAs(UnmanagedType.LPArray)]byte[] name);
在c#函数中调用该函数时,会产生System.DllNotFoundException异常。

注:在win7系统下,函数在c#中声明为[DllImport("test.dll", EntryPoint = "run", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]  
  public static extern IntPtr run([MarshalAs(UnmanagedType.LPArray)]byte[] uml, [MarshalAs(UnmanagedType.LPArray)]byte[] name);
程序可以正常运行。

求助:要在linux系统下运行正常,我该如何在c#中声明该函数。还请各位多多指点!谢谢

------解决方案--------------------
DllNotFoundException
是库没有找到造成的。路径是否正确?
------解决方案--------------------
没搞过mono的PInvoke。。。搜了下,看看下面的资料有没有帮助:

http://www.mono-project.com/Interop_with_Native_Libraries