Search code examples
c++bashshared-librariesldbin

Understanding LD_LIBRARY_PATH and missing shared libraries (for Mujoco)


I recently installed the free trial version of Mujoco 1.31. (This question is more general than this, though; Mujoco is a commercial physics library where one needs to obtain a computer-specific mjkey.txt file to run it.) I have been observing some behavior with the $LD_LIBRARY_PATH which is puzzling me.

Here's the directory of relevant stuff. I'm inside the directory /home/daniel/mjpro131. The mjkey.txt text appears in two places since I had to have a copy in the bin directory to run the code.

$ ls
bin  doc  include  LICENSE.txt  mjkey.txt  model  sample
$ ls -lh bin/
total 2.1M
-rwxrwxr-x 1 daniel daniel  14K Apr 23  2016 compile
-rwxr-xr-x 1 daniel daniel 123K Apr 23  2016 libglfw.so.3
-rwxrwxr-x 1 daniel daniel 1.8M Apr 23  2016 libmujoco131.so
-rw-rw-r-- 1 daniel daniel  876 Apr  3 14:52 mjkey.txt
-rw-rw-r-- 1 daniel daniel  156 Apr  3 14:52 MUJOCO_LOG.TXT
-rwxrwxr-x 1 daniel daniel  30K Apr 23  2016 simulate
-rwxrwxr-x 1 daniel daniel  51K Apr 23  2016 test
$ ls -lh model/
total 12K
-rwxr-xr-x 1 daniel daniel 9.4K Apr 23  2016 humanoid.xml

The getting started instructions say to try the simulator code. (These instructions are for version 1.40 but should still work for 1.31.) I attempted to run the following commands, but it does not work:

$ ./bin/simulate model/humanoid.xml 
./bin/simulate: error while loading shared libraries: ../bin/libmujoco131.so: cannot open shared object file: No such file or directory

Yet when I go inside the bin directory, the simulator code works:

$ cd bin/
$ ./simulate ../model/humanoid.xml 
MuJoCo Pro library version 1.31

This works, and I'd be happy to continue with this, but I really want to understand why my first attempt at this failed. From looking on StackOverflow, I see that the error I got probably deals with the LD_LIBRARY_PATH variable. Here it is:

$ echo $LD_LIBRARY_PATH 
/usr/local/cuda-8.0/lib64:/home/daniel/mjpro131/bin:/home/daniel/mjpro131
$ pwd
/home/daniel/mjpro131
$ ls
bin  doc  include  LICENSE.txt  mjkey.txt  model  sample

Here are the relevant lines of my .bashrc:

export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/daniel/mjpro131/bin:/home/daniel/mjpro131

And I made sure to source it before attempting to run the simulator code. Also, before attempting to run the simulator, I ran sudo ldconfig which was advised by some other StackOverflow questions. Unfortunately, I'm still unable to run the Mujoco simulator when I'm at the top-level directory of mjpro131.

Question: I thought the LD_LIBRARY_PATH should be able to find /home/daniel/mjpro131/bin and any library inside it. However, this doesn't seem to be the case as it can't find libmujoco131.so. Am I missing something obvious here?

I'm using Ubuntu 16.04.


Solution

  • You may not be dealing with an LD_LIBRARY_PATH behavior, but instead a characteristic of the library you're testing.

    Here's a quote from the page for which you provided a link:

    The code samples expect the activation key to be named mjkey.txt and to be in the same directory as the executable, but this can also be changed.

    If you didn't do whatever it takes to change that default behavior, the behavior you are seeing seems pretty consistent with the noted policy.