Linking errors when compiling code with OpenCV Libraries

UPDATED-

Better use this command:

g++ opencv.cpp -o opencv -L `pkg-config --cflags --libs opencv`

The pkg-config command will locate the correct include and library for your source code.
For better handling with OpenCV programming go with an IDE like code::block.

Maybe this tutorial will help you in OpenCV programming with code::block:
How to Setup OpenCV for code :: block in Linux and Windows?


Recently I started using OpenCV and I got similar problem and for me this works really well:

-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_objdetect

Hope it will solve your problem.


You need to add another -L argument specifying the actual location of the OpenCV libraries.