[MonoDevelop] Loading unmanaged shared library

Ian Norton-Badrul ian.norton-badrul at thales-esecurity.com
Mon Jun 7 07:04:34 EDT 2010


On Sat, 2010-06-05 at 06:55 +0100, karen wrote:
> OK, I'll try to be more specific. ;)
> 
> The shared library on Linux, is a derived from a Windows DLL. Apparently the 
> Linux version was (that I can gleam from the release notes) written in C, 
> compiled on Linux on GCC 3.3.1. I have real little information on its 
> construction, aside from that, the header files, and the documentation for 
> the APIs. Calling method is still specified as WINAPI (i.e., stdcall).
> 
> It in turn provides an API to access a USB driver. I have it installed, as I 
> said in /usr/local/lib, also /usr/lib. I have no trouble accessing it using 
> natively compiled C code. The problem is in it being located by my managed 
> wrapper, written in C# and compiled with the MonoDevelop compiler. Written 
> originally on Windows, .Net 3.5, where it runs fine. The problem is in 
> porting it to Linux, with Mono 2.6.
> 
> Functions are declared as:
> 
> [DllImport("FTD2XX.dll")]
> static extern FT_STATUS FT_Open(UInt32 uiPort, ref FT_HANDLE ftHandle);
> 
> Following http://www.mono-project.com/Interop_with_Native_Libraries, I 
> created a .config file (in the same directory as the wrappers assembly to 
> map the original DLL name to the Linux library name:
> 
> <configuration>
>     <dllmap dll="FTD2XX.dll" target="libftd2xx.so" />
> </configuration>
> 
> With no avail. I tried with the full version library name as well, 
> libftd2xx.so.0.4.16.
> 
> I also rewrote the function declarations to explicitly reference the Linux 
> specific library name. In each case the result is the same, 
> DllNotFoundException is thrown. In the attempt with the .config file 
> approach, the error message indicates FTD2XX.dll is not found; with the 
> revised function declarations, the error message indicates libftd2xx.so is 
> not found.

Hi Karen.

You can try to run your mono app under strace, you should be able to see
mono attempt to call dlopen() on various files and see if it chooses
your file.

It could be that the soname of your library does not match it's
filename.

You can print the soname of your library like so:-

$ objdump -p libpng12.so|grep SONAME
  SONAME      libpng12.so.0

In the above case I would need to do 'DllImport("png12")'.

Regards

Ian



More information about the Monodevelop-list mailing list