fatal error: opencv2/core.hpp: No such file or directory compilation terminated in opencv4

user picture user · Mar 1, 2019 · Viewed 12k times · Source

In opencv4 while compiling code, I am getting this error:

fatal error: opencv2/core.hpp: No such file or directory
compilation terminated.

I properly installed opencv4. Why am I getting an error?

Answer

S.S. Anne picture S.S. Anne · Mar 1, 2019

Try installing the -dev or -devel package for OpenCV2 to get the header file.

sudo apt-get install libopencv-core-dev on Debian and Ubuntu, and sudo yum install opencv-devel on Fedora.

Once that's done, append $(pkg-config --cflags opencv) to your compiler command:

export CC="gcc $(pkg-config --cflags opencv)"