Error of installing OpenCV 4.2.0

Hello! I’ve got a problem with the installation of OpenCV 4.2.0 in Ubuntu 18.04.
After finishing the step: ‘& sudo make install’ I’ve finished the installation of OpenCV, but when I am trying to test if OpenCV works well by using the test internal ‘drawing.cpp’, it made a lot of mistakes, like this:

bako@bako-desktop:~/OpenCV/opencv-4.2.0/samples/cpp$ g++ drawing.cpp -o drawing pkg-config opencv --libs --cflags
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc’
to the PKG_CONFIG_PATH environment variable
No package ‘opencv’ found
drawing.cpp:1:10: fatal error: opencv2/core.hpp: No such file or directory
#include “opencv2/core.hpp”
compilation terminated.

How can I solve this king of question? Did I forget any necessary steps during the installation?
I am looking for your answer. Thank you!

Please do check whether this header file is installed on the system.

If yes, then please check if this path is included during code compilation.

You may need to add this to your build script, as mentioned here


I haven’t verified by testing, but that may be the only flag you need for pkgconfig support.