嵌入单声道示例:加载共享库时出错:libmonoboehm-2.0.so.1

embedding mono sample: error while loading shared libraries: libmonoboehm-2.0.so.1

我已经通过 make && make install from source 在 centos 6 上安装了 mono 当我尝试这个样本时: https://github.com/mono/mono/blob/master/samples/embed/teste.c

编译过程中没有发生错误,但是当我运行时我得到了这个:

[root@WOH_Test t01]# gcc -o teste teste.c `pkg-config --cflags --libs mono-2` -lm
[root@WOH_Test t01]# mcs test.cs
[root@WOH_Test t01]# ./teste test.exe
./teste: error while loading shared libraries: libmonoboehm-2.0.so.1: cannot open shared object file: No such file or directory

我不知道问题出在哪里,有什么线索吗?

  1. /usr/local/lib你有什么?如果在命令 make 之前 运行ning autogen.sh 时未使用 --prefix 选项,则库应位于 /usr/local/lib 中。您应该在该目录中看到如下内容:

    me@mypc:/usr/local/lib$ ls -lah libmono-2.0.*
    lrwxrwxrwx. 1 me me 18 dic 19 00:38 libmono-2.0.a -> libmonoboehm-2.0.a
    lrwxrwxrwx. 1 me me 19 dic 19 00:38 libmono-2.0.la -> libmonoboehm-2.0.la
    lrwxrwxrwx. 1 me me 19 dic 19 00:38 libmono-2.0.so -> libmonoboehm-2.0.so
    lrwxrwxrwx. 1 me me 21 dic 19 00:38 libmono-2.0.so.1 -> libmonoboehm-2.0.so.1
    lrwxrwxrwx. 1 me me 25 dic 19 00:38 libmono-2.0.so.1.0.0 -> libmonoboehm-2.0.so.1.0.0
    
  2. 如果您可以在 /usr/local/lib 中看到上述库,则您的问题与 ld 在哪里搜索库有关。从这个问题: CentOS /usr/local/lib system wide $LD_LIBRARY_PATH 我猜 Centos6 默认没有 /usr/local/lib 配置。如果是你的情况,只需使用该问题中提供的解决方案(其中任何一个),你的程序应该可以正常工作。

编辑

根据您的评论,如果您希望 libmonoboehm-2.0.so.1teste 程序处于同一路径,并且您不想触及 Centos6 中的任何其他内容,您可以执行以下操作:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/teste/binary
./teste test.exe

但我想知道当你运行这个命令时你有什么输出:pkg-config --cflags --libs mono-2(好像你已经在你的Centos6中安装了单声道)

总之,如果你能修改你的Centos6,最好的答案是:CentOS /usr/local/lib system wide $LD_LIBRARY_PATH。你这样做一次,你将能够 运行 任何 mono 程序,而不必弄乱 LD_LIBRARY_PATH 环境变量。在您的情况下,您应该执行以下操作:

1. Edit /etc/ld.so.conf
2. Write this: /opt/mono/lib
3. Run ldconfig -v as root
4. Your Centos6 is ready to run your mono programs whenever you wish (even if you restart your Centos6 machine)

结束编辑