5
g++ cv.cpp -o cv -I /usr/local/include/opencv
    -L /usr/local/lib  -lm -lcv -lhighgui -lcvaux

Error:

/usr/bin/ld: cannot find -lcv
collect2: ld returned 1 exit status

Code:

#include <cv.h>
#include <ml.h>
#include <cxcore.h>
//#include <cxtypes.h>
#include <highgui.h>

int main(int argc, char* argv[])
{
    IplImage* img = cvLoadImage( "bal.png" );
    cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
    cvShowImage("Example1", img);
    cvWaitKey(0);
    cvReleaseImage( &img );
    cvDestroyWindow( "Example1" );
    return 0;
}

It's 32 bit,

locate libcv
/usr/lib/libcv.so.2.1
/usr/lib/libcv.so.2.1.0

`pkg-config --cflags --libs opencv`

-I/usr/local/include/opencv
-I/usr/local/include  /usr/local/lib/libopencv_calib3d.so
/usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so
/usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so
/usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so
/usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so
/usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so
/usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so
/usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_ts.so
/usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so

Installed OpenCV-2.4.0 in /usr/local, I also have a system python-opencv. Where am i doing the mistake? What should i do?

vyegorov
  • 21,787
  • 7
  • 59
  • 73
cola
  • 12,198
  • 36
  • 105
  • 165
  • If you are on 64bit system, you should probably use `-L /usr/local/lib64`. Anyway, try to `locate libcv.so` – aland May 04 '12 at 16:37
  • It's 32 bit, `locate libcv` = /usr/lib/libcv.so.2.1 /usr/lib/libcv.so.2.1.0 – cola May 04 '12 at 16:52
  • possible duplicate of [OpenCV on ubuntu 11.10](http://stackoverflow.com/questions/7781302/opencv-on-ubuntu-11-10) – karlphillip May 04 '12 at 20:07

3 Answers3

6

As seen from the changelog published on the OpenCV site (for version 2.2), the library names have changed from version 2.2 onwards, so the library names used to link for version 2.1 cannot be used to compile with version 2.4 (i.e. libcv.so which is linked through -lcv is not valid library name for version > 2.1 as so on ). You need to pass the libraries which are part of the new version of OpenCV (which have been listed through pkg-config command). You can make use of pkg-config to pass the compiler & linker flags something on these lines : g++ cv.cpp -o cv $(pkg-config --cflags --libs opencv).
Hope this helps!

another.anon.coward
  • 11,087
  • 1
  • 32
  • 38
1

You have version 2.1 in /usr/lib while the new installed version 2.4 is in /usr/local/lib, need to fix that and make sure the lib ld finds is the one you compiled/linked for.

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
fireant
  • 14,080
  • 4
  • 39
  • 48
0

I had a similar problem with the opencv 2.4 and was a compatibility issue. If you want to use the latest version, remove previous version of opencv to avoid this problems or lib location's problems when you compile.

Mest
  • 99
  • 2
  • 6