Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some simple opencv files which I wanted to compile on 12.04.

I have installed all the -dev packages

They use:

#include <cv.h>
#include <highgui.h>

at the top of the file.


g++ `pkg-config --cflags --libs opencv` canny.cpp

gives cv.h: No such file or directory

pkg-config seems to list /usr/include/opencv but the directory created at install is /usr/include/opencv2

Is this a bug? Any advice?

share|improve this question
If you think it is a bug then report it to Thanks – Ravi Apr 13 '12 at 3:43

Assuming you've installed the libraries right, the command you're using to compile the code through the terminal is wrong. I've tried it myself, and it doesn't work! Try the following,

g++ canny.cpp -o canny `pkg-config --cflags --libs opencv` 

This line should work fine. Please, try it and let us know.

share|improve this answer

You have to install the package libcv-dev in order to get the old-style header files in /usr/include/opencv/.

share|improve this answer

Replace your header files in the code with this (Assuming your path is "/usr/include/"):

#include <opencv2/opencv.hpp>

and use this to compile

g++ canny.cpp -o canny -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_objdetect
share|improve this answer

you must include "/usr/local/include/opencv" folder in compile time to work.

share|improve this answer
g++ filename.cpp -o outputfile-name `pkg-config --cflags --libs opencv`

Compilation example:

g++ simple.cpp -o sample `pkg-config --cflags --libs opencv` 


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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