Install opencv4 from source
git clone https://github.com/opencv/opencv.git
cd opencv
mkdir build
cd build
cmake ../
make -j 8 # what ever you want
sudo make install
Install pkg-config
brew install pkg-config
pkg-config path
(might not needed)
add a path to you shell's .rc
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
Compile using pkg-config
# you need -std=c++11, and set .pc name which is named opencv4.pc, it is opencv"4".pc, it needs 4 man!!
g++ main.cpp -std=c++11 `pkg-config --cflags --libs opencv4`