Package opencv was not found in the pkg-config search path
Asked Answered
G

13

83

I have installed OpenCV using the instructions in https://help.ubuntu.com/community/OpenCV

$ sudo su
$ sudo apt-get install build-essential
$ sudo apt-get install libavformat-dev
$ sudo apt-get install ffmpeg
$ sudo apt-get install libcv2.3 libcvaux2.3 libhighgui2.3 python-opencv opencv-doc libcv-dev libcvaux-dev libhighgui-dev

now when i execute "pkg-config --cflags --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

how can I resolve this problem?

-------UPDATE-------

OK, I figured out how to solve the problem...

I made a file named "opencv.pc" and copied it to "/usr/local/lib/pkgconfig" Then i added these two lines to ".bashrc":

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

that's it! everything is OK now.

the contents of the file are:

prefix=/usr
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib

Name: opencv
Description: The opencv library
Version: 2.x.x
Cflags: -I${includedir}/opencv -I${includedir}/opencv2
Libs: -L${libdir} -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -lopencv_core -lopencv_ml -lopencv_features2d -lopencv_objdetect -lopencv_flann -lopencv_video -lopencv_highgui

UPDATE - 2014

it seems that the ubuntu community has completed the documentation on installing openCV, all you have to do now is to download the installation script from https://github.com/jayrambhia/Install-OpenCV/blob/master/Ubuntu/opencv_latest.sh and execute it.

Golf answered 10/3, 2013 at 8:14 Comment(4)
Im not sure but I think prefix is where opencv is installed. I compiled it manually and I get the same error as you, so I'm going to try this but changing the prefixBeside
As of 2019, I still used this to fixe opencv on my mac.Prototrophic
After installing libopencv-dev in Ubuntu 20.04, the file opencv4.pc was already automatically present in /usr/local/lib/pkgconfig/. The only thing I had to do was to copy (symlink) this fie and cal it opencv.pcDiatonic
in my case there is no /usr/local/lib/pkgconfigKreis
G
6

it seems that the ubuntu community has completed the documentation on installing openCV,

so all you have to do now is to download the installation script from here and execute it.

don't forget to make it executable:

chmod +x opencv_latest.sh

then

./opencv_latest.sh
Golf answered 4/2, 2014 at 20:26 Comment(3)
Do you know how to uninstall the opencv after installing it with the script above?Mcguire
This solution on its own does not work to install opencv. What needs to be done prior to this step?Subterranean
this does not seem to support the activation of CUDA supportKreis
R
54

with opencv 4.0;

  • add -DOPENCV_GENERATE_PKGCONFIG=ON to build arguments
  • pkg-config --cflags --libs opencv4 instead of opencv
Representational answered 8/10, 2019 at 16:38 Comment(5)
what does this mean?Kreis
later linux releases comes with opencv 4 instead of opencv 3. If your system installed with opencv version 4. then you have to use pkg-config --cflags --libs opencv4 instead of pkg-config --cflags --libs opencvSynagogue
Are you sure the build argument is -DOPENCV_GENERATE_PKGCONFIG=ON and not -D OPENCV_GENERATE_PKGCONFIG=ON ? I think there should be a space after -D or not?Deina
no there' shouldn't be a space betweenRepresentational
As a few of the other answers have stated, for some version of OpenCV 4.X, the flag needs to be -D OPENCV_GENERATE_PKGCONFIG=YES instead of ON.Playroom
P
53

From your question I guess you are using Ubuntu (or a derivate). If you use:

apt-file search opencv.pc

then you see that you have to install libopencv-dev.

After you do so, pkg-config --cflags opencv and pkg-config --libs opencv should work as expected.

Practiced answered 3/2, 2014 at 9:48 Comment(1)
the search retors libopencv-dev on ubnuntu 14.04Mcnary
T
7

When you run cmake add the additional parameter -D OPENCV_GENERATE_PKGCONFIG=YES (this will generate opencv.pc file)

Then make and sudo make install as before.

Use the name opencv4 instead of just opencv Eg:-

pkg-config --modversion opencv4

Tongue answered 22/6, 2020 at 16:9 Comment(1)
Thanks. It's May, 2022 and this fixed the issue with OpenCV 4.5.5 Cheers, ;-)Rhodos
G
6

it seems that the ubuntu community has completed the documentation on installing openCV,

so all you have to do now is to download the installation script from here and execute it.

don't forget to make it executable:

chmod +x opencv_latest.sh

then

./opencv_latest.sh
Golf answered 4/2, 2014 at 20:26 Comment(3)
Do you know how to uninstall the opencv after installing it with the script above?Mcguire
This solution on its own does not work to install opencv. What needs to be done prior to this step?Subterranean
this does not seem to support the activation of CUDA supportKreis
O
3

I installed opencv following the steps on https://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html

Except on Step 2, use: cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=YES -D CMAKE_INSTALL_PREFIX=/path/to/opencv/ ..

Then locate the opencv4.pc file, mine was in opencv/build/unix-install/

Now run: $ export PKG_CONFIG_PATH=/path/to/the/file

Overfeed answered 1/7, 2020 at 11:36 Comment(0)
T
2

Hi first of all i would like you to use 'Synaptic Package Manager'. You just need to goto the ubuntu software center and search for synaptic package manager.. The beauty of this is that all the packages you need are easily available here. Second it will automatically configures all your paths. Now install this then search for opencv packages over there if you found the package with the green box then its installed but else the package is not in the right place so you need to reinstall it but from package manager this time. If installed then you can do this only, you just need to fill the OpenCV_DIR variable with the path of opencv (containing the OpenCVConfig.cmake file)

    export OpenCV_DIR=<path_of_opencv>
Tremayne answered 31/7, 2013 at 20:55 Comment(0)
C
2

I got the same error when trying to compile a Go package on Debian 9.8:

# pkg-config --cflags  -- libssl libcrypto
Package libssl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libssl.pc'

The thing is that pkg-config searches for package meta-information in .pc files. Such files come from the dev package. So, even though I had libssl installed, I still got the error. It was resolved by running:

sudo apt-get install libssl-dev
Corroborate answered 6/4, 2019 at 14:43 Comment(0)
I
2

Writing this answer specially for MacOS users.

First to install opencv use:

brew install opencv 
or brew install opencv@x (x = 2,4)  

We need to have the path of opencv.pc in the PKG_CONFIG_PATH to avoid this error. When you install opencv with brew it says something like this on console

 For pkg-config to find opencv@2 you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/opencv@2/lib/pkgconfig"

As the error suggest the reason is that opencv is not in the PKG_CONFIG_PATH variable. First check what is inside the variable using:

echo $PKG_CONFIG_PATH

To include the location of opencv.pc to the PKG_CONFIG_PATH use this

  echo 'export PKG_CONFIG_PATH="/opt/homebrew/opt/opencv/lib/pkgconfig:$PKG_CONFIG_PATH"' >> ~/.zshrc
Imes answered 1/2, 2022 at 2:10 Comment(0)
M
2

From opencv 4.0:

add -DOPENCV_GENERATE_PKGCONFIG=YES to cmake build arguments.

Use YES, ON is not working anymore.

Example:

cmake -D CMAKE_BUILD_TYPE=RELEASE \
  -D CMAKE_INSTALL_PREFIX=/usr/local \
  -DWITH_V4L=ON \
  -DWITH_LIBV4L=ON \
  -DWITH_FFMPEG=ON \
  -DOPENCV_GENERATE_PKGCONFIG=YES \
  -D BUILD_EXAMPLES=ON ..
Medwin answered 12/12, 2022 at 19:47 Comment(0)
U
0

$ apt-file search opencv.pc $ ls /usr/local/lib/pkgconfig/ $ sudo cp /usr/local/lib/pkgconfig/opencv4.pc /usr/lib/x86_64-linux-gnu/pkgconfig/opencv.pc $ pkg-config --modversion opencv

Ulema answered 6/2, 2021 at 18:55 Comment(0)
U
0

Please try to set the environment in .bashrc:

tomapaxxx@localhost:~$ cat .bashrc

a)export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:~/workspace/usr/local/pkgconfig

export PYTHONPATH=/usr/bin/python2.7:$PYTHONPATH

b)After edition please find the file opencv.pc ,mkdir -p ~/workspace/usr/local/pkgconfig,then copy opencv.pc under the path ~/workspace/usr/local/pkgconfig.

d)source .bashrc under ~/. or ~/.bashrc.

eg: root@localhost:source ~/.bashrc

e)At the end you can use pkg-config --libs --cflags opencv to check whether you can see any information.

f)It is better if you can write information in .bash_profile with ./bashrc.

if [ -f ~/.bashrc ]; then

. ~/.bashrc

    fi

    # User specific environment and startup programs

    PATH=$PATH:$HOME/bin

    export PATH
Undertook answered 9/6, 2022 at 11:40 Comment(0)
D
0
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

cd opencv/
mkdir build
cd build/

#now  Run cmake 
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

check detailed explanation here https://docs.opencv.org/3.4/d7/d9f/tutorial_linux_install.html

Damoiselle answered 21/6, 2022 at 5:57 Comment(0)
K
-1
$ ./configure --enable-libopencv
ERROR: opencv not found using pkg-config


$ cat /usr/lib64/pkgconfig/opencv.pc
# Package Information for pkg-config

prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib64
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 3.1.0
Libs: -L${exec_prefix}/lib64 -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cvv -lopencv_dnn -lopencv_dpm -lopencv_fuzzy -lopencv_hdf -lopencv_line_descriptor -lopencv_optflow -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core
Libs.private: -L/usr/lib64 -lQt5Test -lQt5Concurrent -lQt5OpenGL -L/lib64 -lwebp -lpng -ltiff -ljasper -ljpeg -lImath -lIlmImf -lIex -lHalf -lIlmThread -lgdal -lgstvideo-1.0 -lgstapp-1.0 -lgstbase-1.0 -lgstriff-1.0 -lgstpbutils-1.0 -lgstreamer-1.0 -lucil -lunicap -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lfontconfig -lfreetype -lglib-2.0 -ldc1394 -lv4l1 -lv4l2 -lgphoto2 -lgphoto2_port -lexif -lQt5Core -lQt5Gui -lQt5Widgets -lhdf5_hl -lhdf5 -lz -ldl -lm -ltesseract -llept -lpthread -lrt -lGLU -lGL
Cflags: -I${includedir_old} -I${includedir_new}


$ pkg-config --cflags --libs opencv
-I/usr/include/opencv -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cvv -lopencv_dnn -lopencv_dpm -lopencv_fuzzy -lopencv_hdf -lopencv_line_descriptor -lopencv_optflow -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core


$ uname -a
Linux fedora-23-x64 4.8.13-100.fc23.x86_64 #1 SMP Fri Dec 9 14:51:40 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Kidderminster answered 6/3, 2017 at 8:5 Comment(1)
Please explain your answer instead of just showing commands.Spectacles

© 2022 - 2024 — McMap. All rights reserved.