6

I know that a similar question has been asked before, but none of the suggestions have helped.

I am trying to compile an OpenCV project using C++ in Ubuntu 15.10. I can run the project correctly in Netbeans. But I am supposed to send this to someone who will be using the command line. I can compile the program with the line:

 g++ -ggdb -o convert *.cpp  \`pkg-config --cflags --libs opencv\`

Where convert is the chosen name for the executable. There are no problems after executing this line. But when I run

./convert "image1.tif" "image2.tif"

I get:

  ./convert: error while loading shared libraries: libopencv_imgcodecs.so.3.2: cannot 
open shared object file: No such file or directory

In my .cpp files, I have:

#include "/usr/local/include/opencv2/highgui/highgui.hpp"

The file libopencv_imgcodecs.so.3.2 is in my /usr/local/lib folder. I tried putting -L/usr/local/lib in the command line, but this did not help. Perhaps this file path needs to go in a specific order in the command line? The order mattered for the pkg-config --cflags --libs opencv, which had to come after the -o convert *.cpp.

Amr Eladawy
  • 4,193
  • 7
  • 34
  • 52
Inquisitor
  • 61
  • 1
  • 1
  • 3
  • 3
    I found the answer here: http://answers.opencv.org/question/6732/missing-shared-library/ I had to add: export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib to the .bashrc file. – Inquisitor Apr 01 '17 at 05:21

2 Answers2

3

Just for convenience, as the first comment said, you just need:

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib

if your CMAKE_INSTALL_PREFIX=/usr/local

Hu Xixi
  • 1,799
  • 2
  • 21
  • 29
1

Your libopencv_imgcodecs.so isn't linked correctly. You can check that by using ldd:

$ ldd ./convert
/path/to/program/convert:
        ...
        libopencv_imgcodecs.so.3.2 => not found
        libopencv_imgproc.so.3.2 => not found
        libopencv_core.so.3.2 => not found
        ...

You can find where libopencv_imgcodecs.so is installed:

$ find / -type f -name libopencv_imgcodecs.so.3.2
/usr/local/lib/libopencv_imgcodecs.so.3.2

Save this directory to LD_LIBRARY_PATH variable.

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib
K.Mat
  • 1,341
  • 11
  • 17