cola
cola

Reputation: 12466

Can't compile first opencv program, '/usr/bin/ld: cannot find -lcv'

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?

Upvotes: 5

Views: 10867

Answers (3)

fireant
fireant

Reputation: 14530

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.

Upvotes: 1

Mest
Mest

Reputation: 99

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.

Upvotes: 0

another.anon.coward
another.anon.coward

Reputation: 11395

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!

Upvotes: 6

Related Questions