Use pkg-config with Homebrew installed software

I have installed some libraries with Homebrew but if I use pkg-config it does not find them because there are missing .pc files.

For example, if you do:

brew install opencv

and, after it is installed:

pkg-config --libs opencv

I get this error:

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

This error is caused because Homebrew does not create any opencv.pc.

Is there a way to configure Homebrew to create the .pc files so that all packages installed with brew can be found by pkg-config?


Check with brew ls opencv that there is no opencv.pc installed. I tried it and I have one. If you don't get one, then there is a bug in the package.

Otherwise, check that you are using the correct Homebrew pkg-config. Check with which pkg-config and ls -l $(which pkg-config) where it is coming from.