[Mono-list] Problem with loading native libraries

Alain Frisch alain at frisch.fr
Wed Mar 5 07:00:53 EST 2008


Hello,

I'm new to Mono, so please redirect me to a more appropriate forum if
this mailing list is not appropriate for such questions.

I've a function defined in a native shared library "csml_native.so" that
I'd like to call from Mono. In C#, I define a method with
DllImport("csml_native.so"). However, when the method is called, I get
an unhandled exception:

  System.DllNotFoundException: csml_native.so

Setting the environment variable MONO_LOG_DEVEL to debug as explained on
www.mono-project.com/DllnotFoundException does not produce any output
(I'm using Mono 1.2.4 packaged in Ubuntu).

So I've straced the process and grepped for csml_native. Here's how it 
starts:

> open("/home/frisch/mlfi/applications/csml/test/csml_native.so", O_RDONLY|O_LARGEFILE) = 9
> readlink("/home/frisch/mlfi/applications/csml/test/csml_native.so", 0xbf8736cf, 4096) = -1 EINVAL (Invalid argument)
> open("/lib/tls/i686/sse2/cmov/libcsml_native.so.so", O_RDONLY) = -1 ENOENT (No such file or directory)
> open("/lib/tls/i686/sse2/libcsml_native.so.so", O_RDONLY) = -1 ENOENT (No such file or directory)
> open("/lib/tls/i686/cmov/libcsml_native.so.so", O_RDONLY) = -1 ENOENT (No such file or directory)
 > ...

As can be seen, mono finds the .so file (in the current directory). For 
some reason it seems to interpret it as a symbolic link (though this 
seems to be the case also for managed assemblies that it successfully open).

Here are the lines immediatly after the successfull open:

> open("/home/frisch/mlfi/applications/csml/test/csml_native.so", O_RDONLY|O_LARGEFILE) = 9
> fstat64(9, {st_mode=S_IFREG|0755, st_size=988763, ...}) = 0
> mmap2(NULL, 991232, PROT_READ, MAP_PRIVATE, 9, 0) = 0xb6ee6000
> mprotect(0xb6ee6000, 991232, PROT_READ|PROT_EXEC) = 0
> readlink("/home/frisch/mlfi/applications/csml/test/csml_native.so", 0xbffca61f, 4096) = -1 EINVAL (Invalid argument)
> close(9)                                = 0
> munmap(0xb6ee6000, 988763)              = 0


Here's the output of ldd on the .so file:

>         linux-gate.so.1 =>  (0xffffe000)
>         libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7e9a000)
>         libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7e96000)
>         libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7d4b000)
>         /lib/ld-linux.so.2 (0x80000000)

Any idea what I'm doing wrong?

   Alain



More information about the Mono-list mailing list