2
votes

When I compile a simple program : hello_world.cpp

**I get the error-
**fatal error: cv.h: No such file or directory
compilation terminated.****

Solutions I found but didn't work:

  1. I checked for cv.h and highgui.h if they are there, and got these results:
    /home/snu/OpenCV-2.4.0/include/opencv/highgui.h
    /usr/lib/perl/5.14.2/CORE/cv.h
    /home/snu/OpenCV-2.4.0/include/opencv/cv.h

  2. I checked if opencv is correctly installed by using
    pkg-config opencv --libs, this is what i got :
    -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -lopencv_core -lopencv_ml -lopencv_features2d -lopencv_objdetect -lopencv_flann -lopencv_video -lopencv_highgui

  3. I made some changes in the header files of hello_world.cpp as-
    #include "opencv2/highgui/highgui.hpp"

3
Try with this header #include "opencv2/opencv.hpp" which will include all the header file and compile the code as explained here stackoverflow.com/questions/19899804/…Haris

3 Answers

1
votes

You are probably not compiling correctly. Add the opencv-include folder in the compiler settings.

0
votes

Use CMake to link libraries and include directories. It makes your life easier and also for anyone else who will be extending/reading your code in the future. You will not need to add folders specifically into projects as CMake will do that for you automatically.

For example, to link OpenCV, use the follow lines of code:

FIND_PACKAGE( OpenCV REQUIRED )
TARGET_LINK_LIBRARIES( myProject ${OpenCV_LIBS} )
0
votes

please use the code below for such errors:

#include <opencv/cv.h>

in the place of

#include <cv.h>