Search code examples
monocentos6embedding

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


i've installed mono on centos 6 via make && make install from source when i tried this sample: https://github.com/mono/mono/blob/master/samples/embed/teste.c

no error occured during the compilation, but when i run i got this:

[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

i can't figure where the problem is, any clue?


Solution

    1. What do you have in /usr/local/lib? If you didn't use the --prefix option while running autogen.sh before the command make the libraries should be localed in /usr/local/lib. You should see in that directory something like this:

      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. If you can see the above libraries in /usr/local/lib your problem is related to where is ld searching for libraries. From this question: CentOS /usr/local/lib system wide $LD_LIBRARY_PATH I guess Centos6 does not have by default configuration for /usr/local/lib. If it is your case, just use the provided solutions in that question (any of them) and your program should work fine.

    EDIT

    From your comment if you want libmonoboehm-2.0.so.1 in the same path as the teste program and you do not want to touch anything else in your Centos6 you could do something like the following:

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

    But I wonder what output do you have when you run this command: pkg-config --cflags --libs mono-2 (it seems as if you already had a mono installation in your Centos6)

    Anyhow, if you can modify your Centos6 the best is this answer: CentOS /usr/local/lib system wide $LD_LIBRARY_PATH. You do that once and you will be able to run any mono program without having to mess with the LD_LIBRARY_PATH environment variable. In your case you should do the following:

    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)
    

    END EDIT