Error: ERROR: failed to run: pkg-config "opencv >= 2.3.1" --cflags - Is OpenCV installed?

8 min read

The error message suggests that the OpenCV library is not installed on your system or the installed version is not compatible with the minimum version required by the program.

To resolve this issue, you can follow these steps:

  1. Check if OpenCV is installed by running the following command in your terminal:

    pkg-config --modversion opencv
    

    This command will print the version number of the installed OpenCV library, if it is installed. If it is not installed, you need to install it.

  2. If OpenCV is not installed, you can install it using a package manager like apt (for Debian-based systems) or Homebrew (for macOS). The exact command may vary depending on your operating system.

    For example, on Ubuntu or Debian, you can use the following command:

    sudo apt-get install libopencv-dev
    

    On macOS using Homebrew, you can use the following command:

    brew install opencv
    

    Follow the instructions prompted by the package manager to complete the installation.

  3. After installing OpenCV, rerun the original command or the program that generated the error to check if the issue is resolved.

If you still encounter the same error after following these steps, double-check the version requirement of the program you are trying to run and make sure the installed version of OpenCV meets the requirement. Additionally, ensure that the OpenCV library is properly linked when compiling the program.