Installing OpenCV with CodeBlocks IDE on Ubuntu

EDIT: It was reported by some users that this method no longer works. I will post updated version for installation process shortly.

While using OpenCV on Linux I prefer using IDE as you can easily manage code and files when you are working on significantly bigger project. Following are the steps to configure CodeBlocks IDE on Ubuntu for OpenCV. I will be using opencv2.2 and CodeBlocks 10.5 in this post.

For OpenCV 2.3.1 with CodeBlocks on Ubuntu, refer to recent post

Installing CodeBlocks IDE and OpenCV

You can install both CodeBlocks and OpenCV using Synaptic package manager in ubuntu or just type following command in terminal

  • for CodeBlocks:
  • sudo apt-get install codeblocks
  • for Opencv:
    sudo apt-get install libcv1 libcvaux1 libcvaux-dev libcv-dev libhighgui1 libhighgui-dev opencv-doc
For OpenCV 2.3.1 Installation please refer to recent post

Create CodeBlocks c++ project

Create codeblocks project from File > New > Project. A new project dialog will be opened. In project type select Console Application. Select Next. Now it will prompt you to name your project and select location for project files. Make sure to use GNU GCC compiler when prompted. Now your project creation in complete and you should see the codeblocks window as shown in below pic.

Cofiguring CodeBlocks for OpenCV

Now in menu bar go to Project > Build options. Under Linker tab, add "-lm -lcv -lhighgui -lcvaux"(without quotes) parameters in Other linker options. It should look like following pic.

Now, under Search Directories tab, put the location of your opencv include folder. If you have installed opencv using synaptic package manager or apt-get then most probably it should be /usr/include/opencv/. If codeblocks asks for keeping this directory as a relative path then hit Yes.
It should look like following pic.

Now we are done with the setup. We will check our setup now.
Just build and run the following code. It will create a window named Hello and window will disappear upon hitting ESC.


#include <iostream>
#include <cv.h>
#include <highgui.h>
using namespace std;

int main()
    cvNamedWindow("Hello", 1);
    return 0;


  1. which library shall i use for making image processing program?

    1. I have read your blog its very attractive and impressive. I like it your blog.

      Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

      Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai

  2. To install OpenCV using the terminal on Ubuntu:
    $ su -
    # apt-get update
    # apt-get install build-essential
    # apt-get install libavformat-dev
    # apt-get install x264 v4l-utils ffmpeg
    # apt-get install libcv2.3 libcvaux2.3 libhighgui2.3 python-opencv opencv-doc libcv-dev libcvaux-dev libhighgui-dev

  3. why I can't build that code. error said cannot find -lvc -lhighgui.. need help. thanks :)

  4. It doesn't work ;.

    1. do it from here worked for me