15

I'm on Ubuntu 10.10, and I've just upgraded opencv to 2.4.2.

The problem is that each time I open a new shell and try to compile and run, it compiles but doesn't run due to the following error:

./a.out: error while loading shared libraries: libopencv_calib3d.so.2.4: cannot open shared object file: No such file or directory

As far as I can see, this file is located in /usr/local/lib/!

I can get it to run by running the following beforehand:

export LD_LIBRARY_PATH=/usr/local/lib

How can I fix this issue?

Flyk
  • 1,480
  • 3
  • 18
  • 24
nkint
  • 1,975
  • 7
  • 21
  • 24

1 Answers1

7

/usr/local/lib is not in the default Ubuntu path. You should add it at the end of the LD_LIBRARY_PATH environment variable in /etc/environment. Reboot and the new path will be effective.

You can also set this on a per-user basis in ~/.bashrc

Example (/etc/environment)

LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib

Example (~/.bashrc)

export LD_LIBRARY_PATH="/lib:/usr/lib:/usr/local/lib"
ish
  • 138,666
  • 36
  • 303
  • 312
  • 12
    I upvoted, but actually it seems like running `ldconfig` as root is the "right" way to do this: http://askubuntu.com/a/350076/221408 – j_random_hacker Apr 21 '15 at 14:47
  • [It's best to avoid setting `LD_LIBRARY_PATH` permanently.](http://xahlee.info/UnixResource_dir/_/ldpath.html) – Eliah Kagan Jan 01 '17 at 15:23
  • I downvoted (and upvoted @j_random_hacker's ldconfig response), because `LD_LIBRARY_PATH` is almost always the wrong answer to linker errors and should come with extensive caveats. Just type `sudo ldconfig`. – jma Nov 16 '17 at 12:42