c++linuxubuntushared-librariespanda3d

C++ Executable cannot find library at runtime, even though it's in /usr/lib (On Linux)


I'm creating a game in c++ with the Panda3D framework on Ubuntu. All of the Panda3D shared libraries are in /usr/lib/panda3d and all of the headers are in /usr/include/panda3d. I'm compiling with SCons, but I've tried it with gcc and it's the same, so here are the commands:

g++ -o src/main.o -c -fPIC -O2 -std=gnu++11 -I/usr/include/python2.7 -I/usr/include/panda3d -Iinclude src/main.cpp

g++ -o Test src/main.o -L/usr/lib/panda3d -lp3framework -lpanda -lpandafx -lpandaexpress -lpandabullet -lp3dtoolconfig -lp3dtool -lp3direct -lpthread

And here is the error I get when I run the executable:

./Test: error while loading shared libraries: libp3framework.so.1.11: cannot open shared object file: No such file or directory

There isn't much in the code, just initializing a Panda3D window, so I doubt that's the culprit.

As I said before, the libraries are in /usr/lib/panda3d, I've checked about a million times now and it's driving me crazy. I can't think of a single reason why I would get this error. Any help is appreciated :)

Edit:

I was looking through my files and there's a panda3d.conf file in /etc/ld.so.conf.d with one line: /usr/local/lib/x86_64-linux-gnu/panda3d. Does this have anything to do with it?

Edit #2:

I used the path in the above edit as the library path and got the same results, unfortunately.


Solution

  • I can't think of a single reason why I would get this error.

    The reason is very simple: the dynamic loader hasn't been told to look in /usr/lib/panda3d for shared libraries, and so doesn't.

    You can run your program with:

    LD_DEBUG=files,libs ./Test
    

    and observe which directories the loader is searching.

    panda3d.conf ... with one line: /usr/local/lib/x86_64-linux-gnu/panda3d

    That is the wrong directory (or at least not the one where your libraries are).

    One way to fix this is to correct the above path to /usr/lib/panda3d and run sudo ldconfig.

    Another way is to add -Wl,-rpath=/usr/lib/panda3d to your link line.