I accidentally compiled the sample code given in the OpenCV tarball, and that code compiled. Then I looked into the build script, and I found the following command:
g++ `pkg-config --cflags opencv` $1 -o $2 `pkg-config --libs opencv`
It is actually a script. $1
is the first argument, that is a .cpp file, and $2
is the second which is the output file. I use this script as follow:
./build_cv.sh opencv_test.cpp test
Note: make sure the script file "build_cv.sh" has execute permission. If not, then change its permission by typing:
chmod +x build_cv.sh
Now the problem. I was giving the location of header file and libraries in the first attempt. I have to give the location of headers before giving the source file, and location of the libraries after the output file. This is my experience; maybe some other guy have another way of compiling the code.