OpenCV 2.3.1 with CodeBlocks on Ubuntu 12.04

For Installing OpenCV 2.3.1 on ubuntu 12.04 please refer to previous post

Once the installation is done, install codeblocks as mentioned in previous post

Create a new console application as mentioned in above post and go to Build Options.
Make sure that GNU GCC compiler is selected in compiler drop down option.
Go to Linker Settings tab and Link libraries which are located at /usr/local/lib/ and looks like 'libopncv_*.so'
An example is shown in image below

Now go to Search directories and under Compiler tab add following location
Here is a screenshot

Now we are ready to run OpenCV 2.3.1 on Code Blocks running on Ubuntu 12.04.
Here is a sample code to test the installtion


  1. Hi.. I am getting following errors...
    /home/cpp/img/main.o||In function `main':|
    main.cpp|| undefined reference to `cvNamedWindow'|
    main.cpp|| undefined reference to `cvWaitKey'|
    main.cpp|| undefined reference to `cvDestroyWindow'|
    ||=== Build finished: 3 errors, 0 warnings ===|

    Please tell me what should i do?????

    1. Please check your linker setting as mentioned in the post. Which opencv version are you using?

    2. I have checked linker settings.. Still its not working..
      I am using OpenCV Version 2.1.0-7...

    3. Method mentioned in above blogpost works for opencv 2.3 and higher versions. I would suggest you using opencv 2.3.1 or higher versions as they are latest.
      For opencv 2.1 I guess you will have to soecify few more setting such as include directory etc.

  2. Hi... i am new to ubuntu and opencv...
    I followed the above mentioned steps..
    but i am getting following error....

    -------------- Build: Debug in p2 ---------------

    Linking console executable: bin/Debug/p2
    /usr/bin/ld: cannot find -lcv
    /usr/bin/ld: cannot find -lhigui
    /usr/bin/ld: cannot find -lcvaux
    /usr/bin/ld: cannot find -lcv
    /usr/bin/ld: cannot find -lcvaux
    /usr/bin/ld: cannot find -lhigui
    collect2: ld returned 1 exit status
    Process terminated with status 1 (0 minutes, 0 seconds)
    6 errors, 0 warnings

    can anybody tell what is the problem????

    1. which opencv version are you using?

  3. Hi..
    I am trying to capture image using webcam. When i executed the code its giving me capture as null.
    What could be the problem??
    Please help me.
    Following is the code.


    int main( int argc, char** argv )
    cvNamedWindow( "Example", CV_WINDOW_AUTOSIZE );

    CvCapture* capture = cvCaptureFromCAM(0) ;
    IplImage* frame;

    frame = cvQueryFrame( capture );

    if( 1 ) // !frame
    cvShowImage( "Example", frame );

    char c = cvWaitKey(33);
    if( c == 27 )

    cvReleaseCapture( &capture );
    cvDestroyWindow( "Example" );