gocv icon indicating copy to clipboard operation
gocv copied to clipboard

Package opencv4 was not found in the pkg-config search path

Open kabukky opened this issue 5 years ago • 8 comments

I've followed the installation steps on macOS.

  • Go is at the newest version (go version go1.12.9 darwin/amd64).
  • opencv: stable 4.1.1 (bottled)

Still, I get this error:

go run ./cmd/version/main.go
# pkg-config --cflags  -- opencv4
Package opencv4 was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv4.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv4' found
pkg-config: exit status 1

I've also tried using the dev branch, still the same error.

kabukky avatar Sep 02 '19 15:09 kabukky

I got the same problem just like yours

xiepeixing avatar Sep 10 '19 12:09 xiepeixing

I'm having this problem in the Raspberry as well.

diegobernardes avatar Sep 11 '19 16:09 diegobernardes

Find the path of opencv. If you use brew install on macos, it may be /usr/local/lib and /usr/local/include/opencv. Then build the path in pkg-config. You may use the pc building in pkg-config. Or you can use

export CGO_CXXFLAGS="--std=c++11"
export CGO_CPPFLAGS="-I/usr/local/Cellar/opencv/4.1.0/include"
export CGO_LDFLAGS="-L/usr/local/Cellar/opencv/4.1.0/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dpm -lopencv_face -lopencv_photo -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_dnn -lopencv_plot -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ml -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_flann -lopencv_xobjdetect -lopencv_imgcodecs -lopencv_objdetect -lopencv_xphoto -lopencv_imgproc -lopencv_core"

Then use -tags customenv.

virginiadb avatar Sep 12 '19 01:09 virginiadb

Looks a lot like https://github.com/opencv/opencv/issues/15288

You might want to see if the file opencv.pc or possibly opencv-4.1.1.pc was created by the homebrew install instead? The current Homebrew recipe is supposed to be doing the right thing according to this line https://github.com/Homebrew/homebrew-core/blob/master/Formula/opencv.rb#L61

deadprogram avatar Sep 23 '19 07:09 deadprogram

This appears to be an issue on Debian experimental (which has the 4.x branch) as well

RandomErrorMessage avatar Sep 29 '19 02:09 RandomErrorMessage

It appears the OpenCV people are uninterested in changing this default behavior. Generation of pkg-config files is a non-default build configuration that doesn't seem supported by many methods of distribution.

RandomErrorMessage avatar Oct 03 '19 19:10 RandomErrorMessage

If you use the default homebrew installation of opencv, it should create the needed package config file: https://github.com/Homebrew/homebrew-core/blob/master/Formula/opencv.rb#L60

On other OS choices, you need to have pkg-config installed, and also choose that option for your builds for example, the Makefile that is included with GoCV: https://github.com/hybridgroup/gocv/blob/master/Makefile#L62

If you are using the OpenCV that comes with your distribution, then you will for sure need to handle this differently, by either setting up pkg-config or else using the GoCV "customenv" option: https://github.com/hybridgroup/gocv#custom-environment

deadprogram avatar Oct 14 '19 08:10 deadprogram

I was getting the same error, it seems OpenCV was installed but not linked (I had OpenCV already installed for Python, and that conflict caused an error when brew installing OpenCV, but I did not notice at the time).

This fixed it for me:

brew link --overwrite opencv

CAREFUL: Do it at your own risk since it will overwrite any conflicts found when linking (OpenCV for Python might stop working, not sure)

ugrojo avatar Apr 18 '23 00:04 ugrojo