adding a non standard library path to linux library path

Sometimes when you compile some libraries like opencv, they install the compiled shared libraries in non standard path /usr/local/opencv/lib instead of /usr/lib or /usr/local/lib.  So when you try to compile your code against these libraries, gcc will not be able to locate them or when you are using python bindings, python wont be able to locate them.  The errors will be something like this:

error while loading shared libraries:

You need to add them to linux library path. Create a file /etc/ and put the path of your library in it.


After this run:

sudo ldconfig

Then run sudo ldconfig -v to check if it was located.

If you are not sure about the path of the installed libraries you can use the locate utility. If locate is not able to find the path and you are sure that you have installed it, run this to update the index.

sudo updatedb






Leave a Reply

Your email address will not be published. Required fields are marked *