Monday, August 1, 2011

Linking OpenCV 2 library in DEVC++

In my earlier post I have discussed how to link OpenCV 1.x with devC++. But with latest release of OpenCV version ie. OpenCV 2 or higher the earlier method will not work. This because, OpenCV have changed the directory structure. So lets learn how to link OpenCV 2 or higher library version in DevC++ IDE.
  • Goto Tools -> Compiler option 
  • In the pop up click on the plus button. This means you are adding new compiler setting. Add your fav. name eg - OpenCV2
  • Now you need to add compiler commands. Add -L"C:\OpenCV2.X\lib" -lcxcore2X0 -lcv2X0 -lcvaux2X0 -lhighgui2X0 -lml2X0  where X stands for version. Eg For open CV 2.0 add --L"C:\OpenCV2.0\lib" -lcxcore200 -lcv200 -lcvaux200 -lhighgui200 -lml200 . Similarly for OpenCV2.1 add -L"C:\OpenCV2.1\lib" -lcxcore210 -lcv210 -lcvaux210 -lhighgui210 -lml210
  • Add linker command similarly as above. -lcxcore2X0 -lcv2X0 -lcvaux2X0 -lhighgui2X0 -lml2X0 For open CV 2.0 add --L"C:\OpenCV2.0\lib" -lcxcore200 -lcv200 -lcvaux200 -lhighgui200 -lml200 . Similarly for OpenCV2.1 add -L"C:\OpenCV2.1\lib" -lcxcore210 -lcv210 -lcvaux210 -lhighgui210 -lml210
  • Goto Directories -> C includes. Add  C:\OpenCV2.0\include or C:\OpenCV2.1\include or C:\OpenCV2.2\include what ever version you have. I assume that you have installed openCV in C:\
  •  Goto Directories -> Library. Add  C:\OpenCV2.0\lib or C:\OpenCV2.1\libor C:\OpenCV2.2\lib what ever version you have.
  • Goto Directories -> Library. Add  C:\OpenCV2.0\bin or C:\OpenCV2.1\bin or C:\OpenCV2.2\bin what ever version you have. 
  • Now lets write a sample project for OpenCV. Open New project window  and select "Console Application".
  • Non in Project Option > Compiler chose "OpenCV2".
Thus you have successfully integrated OpenCV with DevC++.

11 comments:

  1. thanks for your blog, am new in openCV, i build a project using ur blog :)
    but still i have two errors they are
    1. cannot find -lcxcore210
    2. ld returned 1 exit status
    how to clear this error? could you help me?

    ReplyDelete
  2. Ramesh .. this is linker error. If you are using DevC++ the don't forget to chose the complier setting for your project.

    ReplyDelete
  3. Hello Ritesh, Thanks for this Integration guide. I just did as you instructed. I would test my OpenCV now. I just wondered why we opened a new project without actually working on it !

    thank you !
    - Pilgrim

    ReplyDelete
  4. hi,
    i just did as instructed, but i'm getting the same error as Ramesh

    full details:

    i ran "OpenCV-2.3.1-win-superpack.exe", and i extracted the contents to C:\New Folder\opencv ,ie, all the android, build, data, include, modules, samples etc folders are in that directory.

    Note that the version is 2.3.1, but in the commands, i used just 230 instead of 2310

    now here are the compiler commands i added:

    -L"C:\New Folder\opencv\lib" -lcxcore230 -lcv230 -lcvaux230 -lhighgui230 -lml230

    and linker commands:

    -lcxcore230 -lcv230 -lcvaux230 -lhighgui230 -lml230

    libraries path:
    C:\New Folder\opencv\build\x86\mingw\lib

    binaries path:
    C:\New Folder\opencv\build\x86\mingw\bin

    since there was no direct folder under the "C:\New Folder\opencv" directory

    include:
    C:\New Folder\opencv\include\opencv


    and then i compiled the sample console application project..

    then i got these errors:


    Compiler: OpenCV
    Building Makefile: "C:\Users\ronnieaka\Desktop\PROJ\openCV\Makefile.win"
    Executing make clean
    rm -f main.o FirstCVproj.exe

    g++.exe -c main.cpp -o main.o -I"lib/gcc/mingw32/3.4.2/include" -I"include/c++/3.4.2/backward" -I"include/c++/3.4.2/mingw32" -I"include/c++/3.4.2" -I"include" -L"C:\New Folder\opencv\lib" -lcxcore230 -lcv230 -lcvaux230 -lhighgui230 -lml230

    g++.exe: -lcxcore230: linker input file unused because linking not done
    g++.exe: -lcv230: linker input file unused because linking not done
    g++.exe: -lcvaux230: linker input file unused because linking not done
    g++.exe: -lhighgui230: linker input file unused because linking not done

    g++.exe: -lml230: linker input file unused because linking not done

    g++.exe main.o -o "FirstCVproj.exe" -L"lib" -L"C:/New Folder/opencv/build/x86/mingw/lib" -lcxcore230 -lcv230 -lcvaux230 -lhighgui230 -lml230

    C:\Dev-Cpp\Bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lcxcore230
    collect2: ld returned 1 exit status

    make.exe: *** [FirstCVproj.exe] Error 1

    Execution terminated


    please help me.. i really need OpenCV up and running. I don't wanna use MS VC++, its too bloated and takes too much time and memory on running.

    ReplyDelete
  5. HI RITESH,
    I'm Nandhini.
    I'm using OpenCV2.0 and Dev C++. i followed the same intructions by you to configure both. this is my program.

    #include
    #include

    int main() {

    // read an image
    cv::Mat image= cv::imread("image.jpg");
    // create image window named "My Image"
    cv::namedWindow("My Image");
    // show the image on window
    cv::imshow("My Image", image);
    // wait key for 5000 ms
    cv::waitKey(5000);

    return 1;
    }
    i got this error
    1. cc1plus.exe C:\Dev-Cpp\cc1plus.exe unrecognized command line option "-fLC:\OpenCV2.0\lib"
    2. C:\Dev-Cpp\Makefile.win [Build Error] [main.o] Error 1
    also say the location where i need to store "img.jpg"

    ReplyDelete
  6. there is one missing, C++ Includes. If you're using C++, you need to add new "include" in C++ Include: C:\OpenCV2.1\include\opencv. This will fix the error ;-)

    ReplyDelete
  7. no error not fixed plz help

    i m using open cv 2.4.2

    ReplyDelete
  8. Hey great post, I truly enjoyed reading it! Thanks for the cool informative post. Airport Taxi Toronto

    ReplyDelete
  9. whn i type my code .....after compilation there is no error but i am not able to run my program bcoz of warning "source code not compiled"............i compiled my source code bt still the same problem
    pls tell me what wrong i am dng

    ReplyDelete
  10. whn i type my code .....after compilation there is no error but i am not able to run my program bcoz of warning "source code not compiled"............i compiled my source code bt still the same problem
    pls tell me what wrong i am dng

    ReplyDelete