Wednesday, June 3, 2009

OpenCV shared libraries error

If you installed opencv on your linux machine and are able to compile opencv programs but cannot run them and are receiving the following error :

error while loading shared libraries: libcxcore.so.2: cannot open shared object file: No such file or directory

This means that the program is not able to locate the shared libraries it needs to execute. To sort this out you to have set the LD_LIBRARY_PATH environment variable to the path of your opencv lib directory. This directory should be located in your opencv installation directory(if you installed opencv using the tar rather than using your linux distribution repositories). You can do this by the following command (assuming you have installed opencv in your user directory in a folder named "opencv" :

export LD_LIBRARY_PATH=/home/{username}/opencv/lib/

If you are using the eclipse IDE and getting the same error then to fix it you need to open the Run configurations dialogue box which is located in the run menu, select the environment tab and add a new variable named LD_LIBRARY_PATH with value as described above.

17 comments:

  1. Thanks you so much !!

    ReplyDelete
  2. I've installed opencv using repositories at /usr/local/include/opencv.
    I get the same error as you've specified. I dont find any lib folder in opencv.
    But i fonund that shared file at:
    /usr/local/lib
    so what should i do?
    please help.

    ReplyDelete
  3. {Specifically in reply to pratik069}:

    Well it's not the best solution.
    When you build opencv by yourself, after issuing the 'make install' command, you'll have the libraries in /usr/local/lib and every thing is supposed to be fine by definition, BUT usually is not and you encounter the error mentioned here.
    To solve this:
    1- add the path '/usr/local/lib' to the file '/etc/ld.so.conf' (it should be there already)
    2- sudo ldconfig

    And that's it!

    ReplyDelete
    Replies
    1. Excuse me, what is the file name must have the path '/ usr / local / lib'?

      "ld.so.conf" is the name of a folder ??

      "It ld.so.conf" is not a folder in my folder "/ etc".

      Only this the "/etc/ld.so.conf.d" folder and files are in "libc.conf" and "libc.conf" ... the two files have the path "/ usr / local / lib".

      Delete
  4. Great! Thank you.

    ReplyDelete
  5. you saved my life.

    ReplyDelete
  6. You're my hero. Saved me from a long night of googeling

    ReplyDelete
  7. Brilliant! This shows up top when Googling the error, and no doubt saved me a lot of head scratching. Thanks so much!

    ReplyDelete
  8. do I have to run this command every time ? It works first time but when I close the terminal and open a new one gives the same error

    ReplyDelete
  9. thanks dude.. it worked

    ReplyDelete
  10. Thank you very much for this information.. I got very perfect soluton for face detection

    ReplyDelete
    Replies
    1. Hi Maratha, it worked your project ?? the detection of faces.

      Delete
  11. ThankYou very much.
    You have solved my problem..

    ReplyDelete