For OpenCV 2.4.x

cd /path/to/opencv/samples/c/

For OpenCV 3

cd /path/to/opencv/samples/cpp/

Compile

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

run

./facedetect