You are on page 1of 8

DEV C

The guide below is obsolete. Use


CMake to generate makefiles for your
OpenCV-based project and then
import those makefiles to DevC++ or
other development environment
Settings
We will suppose that the OpenCV library is installed in the C:\Program
Files\OpenCV directory. Now, we have to configure DevCpp that he can take into
account, all the includes files (.h), all the static libraries in OpenCV (.lib), and all the
dynamic library (.dll) useful for the execution and not for the compilation.
This configuration has been tested with the version 4.9.9.x of DevCPP.
First of all, you have to indicate the header files you want to add. To do that, select
Tools->Compiler Options.

.
Then click on the plus sign to add a new compiler (in fact, only some different
options) named here, OpenCV.

To finish, on the section Add the following ... write : -L"C:\Program


Files\OpenCV\lib" -lcxcore -lcv -lcvaux -lhighgui -lml -lcvcam. Or the following
for OpenCV 2.1 -L"C:\OpenCV2.1\lib" -lcxcore210 -lcv210 -lcvaux210
-lhighgui210 -lml210

Include files configuration


Next, click on Directories and then on C Includes to add all the headers, located in
some C:\Program Files\OpenCV subdirectories as shown in the picture.
For OpenCV2.x, you will notice that there are changes in the overall directory
structure and hence you won't find the folders shown in the image below.
You only need to add C:\Program Files\OpenCV2.x\include\opencv in the
include tab to get things to work.
Of course, if you want to write C++ programs, do the same thing on the C++
Includes tab.

Static library files configuration


The following picture shows the static libraries paths to add.For OpenCV2.x there
is no otherlibs\highgui folder and hence just adding C:\Program

FIles\OpenCV2.x\bin is sufficient.

Dynamic library files configuration

And to finish, add the bin directory where the dlls are:

Test
Let us choice a C program on the samples directory of OpenCV and try to execute
it by typing F9. As you can see, all is OK.

That's all folk. I hope this short tuto was useful.

How To Compile OpenCV based programs in Linux


How to compile C on Linux ?

You need to setup the PKG_CONFIG_PATH variable. For example (assuming you
are using a sh-based shell, like bash or zsh):

cd/where/you/have/the/source/code
PKG_CONFIG_PATH=/where/you/have/installed/opencv/lib/pkgconfig:$
{PKG_CONFIG_PATH}
exportPKG_CONFIG_PATH

You can check that the PKG_CONFIG_PATH is correct by doing either:


pkgconfigcflagsopencv
pkgconfiglibsopencv

You must have something like:


$pkgconfigcflagsopencv
I/where/you/have/installed/opencv/include/opencv
$pkgconfiglibsopencv
L/where/you/have/installed/opencv/liblcxcorelcvlhighgui
lcvaux

How to compile and link some OpenCV based program on Linux ?

The best way is to use pkg-config. Just define the correct PKG_CONFIG_PATH:

PKG_CONFIG_PATH=/where/you/have/installed/opencv/lib/pkgconfig:$
{PKG_CONFIG_PATH}
exportPKG_CONFIG_PATH

And then, compile as below:


gcc`pkgconfigcflagsopencv``pkgconfiglibsopencv`omy
opencvprgmmyopencvprgm.c

Simpler way is as below:


gcc`pkgconfigcflagslibsopencv`omyopencvprgmmy
opencvprgm.c

If those two fails, try this:

gccI/where/you/have/installed/opencv
L/where/you/have/installed/opencvlcvlhighguilstdc++\
omyopencvprgmmyopencvprgm.c

How to compile OpenCV with some libraries not in standard path on Linux?

The solution is to use the CFLAGS, CPPFLAGS and LDFLAGS environment variables at
configure time. For example, if you have ffmpeg library in one of your own
directories, you can do (all on one command line):

./configureCFLAGS=I/where/is/ffmpeg/includeCPPFLAGS=
I/where/is/ffmpeg/includeLDFLAGS=L/where/is/ffmpeg/lib

What if I get an error about OpenCV libraries when running a program?

If an error occurs that 'a library cannot be found' during compilation on Fedora
systems:
o

create a file called opencv.conf in /etc/ld.so.conf.d/ which contains the path


to your opencv libraries (by default /usr/local/lib).

run ldconfig as root.

Or, add the location of the OpenCV libraries to your LD_LIBRARY_PATH (should
work on most systems including Fedora)
For additional help on FFMpeg compilation: http://freeshells.ch/~phoenix/ocv.htm

You might also like