在Ubuntu的单声道和非托pipe代码

我使用在Ubuntu 12 x64上运行的Mono 2.10。 现在我需要知道如何使用非托pipe代码。

[DllImport("libc.so")] public static extern int getpid (); 

而且,在下一步我有:

 getpid(); 

我收到这个错误

 $ 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 

我一直试图解决这个问题很长一段时间,但没有任何我试过帮助我。 我用:

  dlopen("libc.so", RTLD_NOW); 

也许我需要libc.so编译为X64?

Solutions Collecting From Web of "在Ubuntu的单声道和非托pipe代码"

它应该是

[DllImport("libc.so.6")]

要不就

[DllImport("libc")]

“libc”是/ etc / mono / config的别名,在GNU / Linux系统上: ... <dllmap dll="libc" target="libc.so.6" os="!windows"\> ...

解决这个在x64位Ubuntu的12

 cd /lib/x86_64-linux-gnu ln -s libc.so.6 libc.so 

为了解决Raspbian在树莓派与单声道4.0.2编译从一个tarball,我做到了这一点

 sudo cp /lib/arm-linux-gnueabihf/libc.so.6 /lib/libc 

/lib是默认搜索文件夹之一