Moep Meep Moep Meep - 1 year ago 79
Linux Question

Compiling works, starting not - "standard path"?

I want to use SFML with C++ under Ubuntu OS. I create two debug/release shared Libarys with cmake (by this tutorial)

I can compile and link my test application without giving any information about a path. So I think everything is alright with the standard path

g++ -c main.cpp

g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system

but when I start now my application with ./sfml-app it said

./sfml-app: error while loading shared libraries: cannot open shared object file: No such file or

this confusing me. Because I think /usr/local/lib is the standard path and when I add this path during compiling

g++ main.o -o sfml-app -L /usr/local/lib -lsfml-graphics
-lsfml-window -lsfml-system

it works. But it should work also without giving information with -L

So what could be the Problem? I have made this before reinstalling Ubuntu. And on my old system it works well, can start my application by ./ terminal and also double clicking.

when I add in the console

export LD_LIBRARY_PATH=$PATH:/usr/local/lib

I can start the application from the console. but only in the specific one. I want the application starts always also by double click (not only from terminal). How can I add the Libary "systemwide" ?

Answer Source

You need to add /usr/local/lib to a file in /etc/ and then call ldconfig to rebuild its cache.

One way of doing it:

sudo sh -c 'echo "/usr/local/lib" > /etc/'
sudo ldconfig

Then you should be able to compile without -L /usr/local/lib nor use export LD_LIBRARY_PATH=$PATH:/usr/local/lib.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download