0

The problem written below the line is solved but i m facing a new related problem. Slightly different from before, I am compiling and linking the sample OpenCV code as:

g++ facedetect.cpp -o facedetection -I /home/harsh/Downloads/OpenCV-2.0.0/include/opencv/ -L/home/harsh/Downloads/OpenCV-2.0.0/lib/ -lcv -lcxcore -lcvaux -lml -lhighgui

That doesn't give any errors now, but when I run the executable using

./facedetection

i get this error:

./facedetection: error while loading shared libraries: libcv.so.2.0: cannot open shared object file: No such file or directory

And when I do symbolic linking, using:

ln -s libcv.so libcv.so.2.0

Then the error is:

ln: failed to create symbolic link 'libcv.so.2.0': File exists

Don't know how to get around this.

Thanks in advance..

IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII

I am trying to create a linux executable of a sample OpenCV program that will be linked dynamically with .so files and will be executed on a machine where OpenCV is not installed, but the .so files will be present on that linux machine.

I have searched many posts regarding this but still am unsuccessful.

I compiled opencv like this:

cd OpenCV-2.0.0/
cmake -DBUILD_SHARED_LIBS=ON .
make

Then all the compiled libraries were created in OpenCV-2.0.0/lib

Then, in the samples/c directory, I did this:

g++ facedetect.cpp -o facedetection -I /home/harsh/Downloads/OpenCV-2.0.0/include/opencv/ -L/home/harsh/Downloads/OpenCV-2.0.0/lib/ -llibcv -llibcxcore -llibcvaux -llibml -llibhighgui

But Errors are :

/usr/bin/ld: cannot find -llibcv
/usr/bin/ld: cannot find -llibcxcore
/usr/bin/ld: cannot find -llibcvaux
/usr/bin/ld: cannot find -llibml
/usr/bin/ld: cannot find -llibhighgui
collect2: ld returned 1 exit status
1
  • Harsh - You've asked a bunch of questions and many of them have good answers. You should reward the answerers with some rep and a checkmark by marking some of them as the accepted answer!
    – mbauman
    Apr 16, 2012 at 22:24

1 Answer 1

4

Use -lcv, -lcxcore, etc.

To link to libfoo.so, the flag is -lfoo, without the lib part.

If your libraries aren't in the default runtime library search path (how this is set/managed depends on your OS and distribution), you need to inform the dynamic linker as to where they are located. (Just like you have to do so when you compile by adding -L flags.)

On Linux, this is done by setting the environment variable LD_LIBRARY_PATH, e.g.:

export LD_LIBRARY_PATH=/home/harsh/Downloads/OpenCV-2.0.0/lib/:$LD_LIBRARY_PATH
./your_app
2
  • Thanks a lot Mat, do you have any idea about my new issue?
    – Harsh
    Apr 17, 2012 at 7:12
  • Edited, but please do some research, that's ask and answered very, very often.
    – Mat
    Apr 17, 2012 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.