I'm using Mono 2.10 running on Ubuntu 12 x64. Now I need to know how to use unmanaged code.
[DllImport("libc.so")]
public static extern int getpid ();
And, in the next step I have:
getpid();
and I recieve this errorL
$ MONO_LOG_LEVEL="debug" MONO_LOG_MASK="dll" mono libc_test.exe
Mono: DllImport attempting to load: 'libc.so'.
Mono: DllImport loading library: '/home/ibaranov/Documents/MONO/libc_test/libc_test/bin/Debug/libc.so'.
Mono: DllImport error loading library '/home/ibaranov/Documents/MONO/libc_test/libc_test/bin/Debug/libc.so: cannot open shared object file: No such file or directory'.
Mono: DllImport loading library: '/home/ibaranov/Documents/MONO/libc_test/libc_test/bin/Debug/libc.so'.
Mono: DllImport error loading library '/home/ibaranov/Documents/MONO/libc_test/libc_test/bin/Debug/libc.so: cannot open shared object file: No such file or directory'.
Mono: DllImport loading location: 'libc.so'.
Mono: DllImport error loading library: '/usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header'.
Mono: DllImport loading location: 'libc.so'.
Mono: DllImport error loading library: '/usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header'.
Mono: DllImport loading: 'libc.so'.
Mono: DllImport error loading library '/usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header'.
Mono: DllImport unable to load library '/usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header'.
Mono: DllImport attempting to load: 'libc.so'.
Mono: DllImport loading library: '/home/ibaranov/Documents/MONO/libc_test/libc_test/bin/Debug/libc.so'.
Mono: DllImport error loading library '/home/ibaranov/Documents/MONO/libc_test/libc_test/bin/Debug/libc.so: cannot open shared object file: No such file or directory'.
Mono: DllImport loading library: '/home/ibaranov/Documents/MONO/libc_test/libc_test/bin/Debug/libc.so'.
Mono: DllImport error loading library '/home/ibaranov/Documents/MONO/libc_test/libc_test/bin/Debug/libc.so: cannot open shared object file: No such file or directory'.
Mono: DllImport loading location: 'libc.so'.
Mono: DllImport error loading library: '/usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header'.
Mono: DllImport loading location: 'libc.so'.
Mono: DllImport error loading library: '/usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header'.
Mono: DllImport loading: 'libc.so'.
Mono: DllImport error loading library '/usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header'.
Mono: DllImport unable to load library '/usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header'.
Hello Linux!
Mono: DllImport attempting to load: 'libc.so'.
Mono: DllImport loading library: '/home/ibaranov/Documents/MONO/libc_test/libc_test/bin/Debug/libc.so'.
Mono: DllImport error loading library '/home/ibaranov/Documents/MONO/libc_test/libc_test/bin/Debug/libc.so: cannot open shared object file: No such file or directory'.
Mono: DllImport loading library: '/home/ibaranov/Documents/MONO/libc_test/libc_test/bin/Debug/libc.so'.
Mono: DllImport error loading library '/home/ibaranov/Documents/MONO/libc_test/libc_test/bin/Debug/libc.so: cannot open shared object file: No such file or directory'.
Mono: DllImport loading location: 'libc.so'.
Mono: DllImport error loading library: '/usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header'.
Mono: DllImport loading location: 'libc.so'.
Mono: DllImport error loading library: '/usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header'.
Mono: DllImport loading: 'libc.so'.
Mono: DllImport error loading library '/usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header'.
Mono: DllImport unable to load library '/usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header'.
Unhandled Exception: System.DllNotFoundException: libc.so
at (wrapper managed-to-native) libc_test.LibC:getpid ()
at libc_test.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: libc.so
at (wrapper managed-to-native) libc_test.LibC:getpid ()
at libc_test.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
I've been trying to resolve this problems for a long time, but nothing I have tried helps me. I use:
dlopen("libc.so", RTLD_NOW);
Maybe I need libc.so compiled for x64?