# Problem with opencv c++ compilation

**URL:** <https://forum.opencv.org/t/problem-with-opencv-c-compilation/4484>\
**Category:** C++\
**Tags:** build\
**Created:** [July 27, 2021, 8:11am UTC](https://forum.opencv.org/t/problem-with-opencv-c-compilation/4484 "2021-07-27T08:11:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anjulo](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@anjulo](https://forum.opencv.org/u/anjulo)\
**Post date:** [July 27, 2021, 8:11am UTC](https://forum.opencv.org/t/problem-with-opencv-c-compilation/4484/1 "2021-07-27T08:11:07Z")

</div>

Hello,

After OpenCV installation using [this](https://github.com/milq/milq/blob/master/scripts/bash/install-opencv.sh) shell script, I’m facing problems when I try to run some a simple example c++ OpenCV code, although a python simple example works.

It’s a simple “imread–\>imshow” code, nothing complicated. The problem appears to be a header file problem.  
Here is the error message I’m getting.

```auto
anjulo@imac:~$ make cpp
g++ cpp.cpp -o cpp `pkg-config opencv --cflags --libs`
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
cpp.cpp:1:10: fatal error: opencv2/core.hpp: No such file or directory
    1 | #include <opencv2/core.hpp>
      | ^ ~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:4: cpp] Error 1

```

I have found after some searching the command `pkg-config opencv --cflags --libs` should tell me where the headers or libs are. But it’s giving me part of the error above.

```auto

anjulo@imac:~$ pkg-config --libs opencv
Package opencv4 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

```

I would appreciate any help to solve this problem.  
I’m running on Ubuntu 20.04

---

<div class="post-metadata">

**Author:** ![legow00](https://avatars.discourse-cdn.com/v4/letter/l/ccd318/32.png) [@legow00](https://forum.opencv.org/u/legow00)\
**Post date:** [July 27, 2021, 10:01am UTC](https://forum.opencv.org/t/problem-with-opencv-c-compilation/4484/2 "2021-07-27T10:01:58Z")

</div>

Did you add the include path to your makefile?  
Default install location for OpenCV is /usr/local.  
Try to add this to your make file:

INCLUDE = -I/usr/local/opencv4

legow00
