Opencv: 4.0.0 does not produce pkgconfig file

Created on 13 Nov 2018  ·  40Comments  ·  Source: opencv/opencv

System information (version)
  • OpenCV => 4.0.0-rc
  • Operating System / Platform => Ubuntu 18.10
  • Compiler => gcc 8.2.0 / gcc 6
Detailed description

I did cmake ...Then make and then make install
and it does not generate opencv.pc file.

If I use same commands for version 3.4.3 then the file is created.

Another thing
if I link with pkgconfig then it links to librarys with no version numbers.
so installing 4.0.0-rc after 3.4.3 makes pkgconfig unusable.
it would be nice if there were multiple opencv.pc files like opencv3.4.pc opencv4.pc

builinstall question (invalid tracker) wontfix

Most helpful comment

I had the same issue, thankfully I found this thread, and I must agree, not everyone uses cmake.
For anyone that stumbles upon this thread with the same issue, I used
cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=YES -D CMAKE_INSTALL_PREFIX=/usr/local ..

The key here being: -D OPENCV_GENERATE_PKGCONFIG=YES
Then continue build and install as normal. I've checked and it does seem that OpenCV does install the .pc file now, so no need to manually copy it over. The package will be installed named as "opencv4", so use pkg-config --cflags opencv4.

All 40 comments

Pkg-config has very limited functionality, so this support has been dropped.

Use CMake with find_package(OpenCV) instead (with multiple version selection, "on the fly" configuration via script language, etc).

Changes are here:

  • #12897 #12896
  • and here

Is there a way to reintroduce pkg-config support? The .pc files that are currently generated seem to work for most settings and not everyone is using cmake. It seems to me that just having a list of libraries that OpenCV depends on as well as the information where the header and .so files are is already sufficient for most use cases with pkg-config. Or is there any limitation in this regard?

Option OPENCV_GENERATE_PKGCONFIG=ON generates the '.pc' file. I think also it should be generated by default in *nix systems where pkg-config is used. I tested my binary files with ldd and they are linked right. It is just development time when conflicts can occur. And I think same problems can occur with cmake also. It is possible to be more specific than just -llib. its possible to specify libs exactly by .so file.

CMakeLists.txt :

OCV_OPTION(OPENCV_GENERATE_PKGCONFIG  "Generate .pc file for pkg-config build tool (deprecated)" ON)

it doesn't work

@codenoid i believe the argument for that option is actually YES

ffmpeg relies on .pc files for opencv library dependency, FWIW...

Also as a note "make install" doesn't install the .pc file, even if it's generated :|

Also as a note "make install" doesn't install the .pc file, even if it's generated :|

have you managed to install the .pc file?

Yeah I just manually copied it in. :|

On Tue, Jan 15, 2019 at 2:20 PM Favi0 notifications@github.com wrote:

Also as a note "make install" doesn't install the .pc file, even if it's
generated :|

have you managed to install the .pc file?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/opencv/opencv/issues/13154#issuecomment-454555451,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAw0IVOZFkcmQtjPGnwDjxWhzJoO-dxks5vDkYegaJpZM4Ycby9
.

I had the same issue, thankfully I found this thread, and I must agree, not everyone uses cmake.
For anyone that stumbles upon this thread with the same issue, I used
cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=YES -D CMAKE_INSTALL_PREFIX=/usr/local ..

The key here being: -D OPENCV_GENERATE_PKGCONFIG=YES
Then continue build and install as normal. I've checked and it does seem that OpenCV does install the .pc file now, so no need to manually copy it over. The package will be installed named as "opencv4", so use pkg-config --cflags opencv4.

System information (version)
  • OpenCV => 4.0.0-rc
  • Operating System / Platform => Ubuntu 18.10
  • Compiler => gcc 8.2.0 / gcc 6
Detailed description

I did cmake ...Then make and then make install
and it does not generate opencv.pc file.

If I use same commands for version 3.4.3 then the file is created.

Another thing
if I link with pkgconfig then it links to librarys with no version numbers.
so installing 4.0.0-rc after 3.4.3 makes pkgconfig unusable.
it would be nice if there were multiple opencv.pc files like opencv3.4.pc opencv4.pc

opencv 4.0.1 has his question too, after making install , there is no opencv.pc generated, even no pkgconfig file

I had the same issue, thankfully I found this thread, and I must agree, not everyone uses cmake.
For anyone that stumbles upon this thread with the same issue, I used
cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=YES -D CMAKE_INSTALL_PREFIX=/usr/local ..

The key here being: -D OPENCV_GENERATE_PKGCONFIG=YES
Then continue build and install as normal. I've checked and it does seem that OpenCV does install the .pc file now, so no need to manually copy it over. The package will be installed named as "opencv4", so use pkg-config --cflags opencv4.

I did it as you told but there was still no pkgconfig nor opencv.pc ...

I added the "-D OPENCV_GENERATE_PKGCONFIG=YES" flag, ran cmake, make, and found:

.../unix-install/opencv4.pc

As mentioned by others, "make install" didn't copy the file anywhere under /usr/local.
I can't glean where opencv4.pc should go by merely reading the pkg-config man page -- some place under /usr/local, but exactly where?

Also had the same problem where make install didn't copy over opencv4.pc, but I was using the 4.1.0 zip from the release page.

@UberEclectic @Kevin-Mok The opencv4.pc file should be copied to /usr/local/lib/pkgconfig. Don't forget to 'sudo ldconfig', for making sure the recently installed OpenCV libraries are correctly taken into account. RC

I had the same issue, thankfully I found this thread, and I must agree, not everyone uses cmake.
For anyone that stumbles upon this thread with the same issue, I used
cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=YES -D CMAKE_INSTALL_PREFIX=/usr/local ..

The key here being: -D OPENCV_GENERATE_PKGCONFIG=YES
Then continue build and install as normal. I've checked and it does seem that OpenCV does install the .pc file now, so no need to manually copy it over. The package will be installed named as "opencv4", so use pkg-config --cflags opencv4.

It did not install .cp file in my case.

Yeah I just manually copied it in. :|

On Tue, Jan 15, 2019 at 2:20 PM Favi0 @.*> wrote: Also as a note "make install" doesn't install the .pc file, even if it's generated :| have you managed to install the .pc file? — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#13154 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAw0IVOZFkcmQtjPGnwDjxWhzJoO-dxks5vDkYegaJpZM4Ycby9 .

How did you do that?, In my case it even have not created opencv.cp file!

Here's how I do it FWIW opencv 3.4.5

do_make_and_make_install
cp unix-install/opencv.pc $PKG_CONFIG_PATH

On Mon, Apr 29, 2019 at 10:26 AM s notifications@github.com wrote:

Yeah I just manually copied it in. :|
… <#m_9070919798374828714_>
On Tue, Jan 15, 2019 at 2:20 PM Favi0 @.*> wrote: Also as a note
"make install" doesn't install the .pc file, even if it's generated :| have
you managed to install the .pc file? — You are receiving this because you
commented. Reply to this email directly, view it on GitHub <#13154
(comment)
https://github.com/opencv/opencv/issues/13154#issuecomment-454555451>,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAw0IVOZFkcmQtjPGnwDjxWhzJoO-dxks5vDkYegaJpZM4Ycby9
.

How did you do that?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/opencv/opencv/issues/13154#issuecomment-487647192,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAADBUGSALBP6IJAXOVIOLTPS4OSLANCNFSM4GDRXS6Q
.

useful if not using CMake in projects that use OpenCV

don't say that is deprecated [1] please

[1]
https://github.com/opencv/opencv/commit/73f65b1ccf220572f8cbad6fe06d19f313892db5

On 4.1.0, and the below does not generate pc file
cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=YES -D CMAKE_INSTALL_PREFIX=/usr/local ..

With 4.1.0, got it functional. I found the mistake in the command provided earlier. Need to use ON, instead of YES.

OPENCV_GENERATE_PKGCONFIG=ON

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

useful if not using CMake in projects that use OpenCV

don't say that is deprecated [1] please

[1]
[73f65b1](https://github.com/opencv/opencv/commit/73f65b1ccf220572f8cbad6fe06d19f313892db5)

I change my point of view maybe can be called deprecated ...

So the -D OPENCV_GENERATE_PKGCONFIG=ON option in cmake is deprecated now? How can we get the pkgconfig and opencv.pc files then?

So the -D OPENCV_GENERATE_PKGCONFIG=ON option in cmake is deprecated now? How can we get the pkgconfig and opencv.pc files then?

if you not explicitly add OPENCV_GENERATE_PKGCONFIG=ON is not generated .

I added to my %cmake

-DOPENCV_GENERATE_PKGCONFIG=ON \
-DOPENCV_PC_FILE_NAME=opencv.pc \

For cmake files be installed in default cmake folder I add :

-DOPENCV_CONFIG_INSTALL_PATH=%{_libdir}/cmake/OpenCV \

Please don't force everyone to use CMAKE. Many projects don't use CMAKE and for good reasons.

So I installed the AUR repository version of opencv. That installation didn't generate any opencv.pc . One of my project (in C) is using 'pkg-config opencv --libs' as one of the make options. Is there a way to generate this opencv.pc without cmaking from this repository? I do want to have two version of opencv, one managed by Pacman and a manual install, installed on my arch.

For cmake files be installed in default cmake folder I add :

-DOPENCV_CONFIG_INSTALL_PATH=%{_libdir}/cmake/OpenCV \

I had a bug report https://bugzilla.redhat.com/show_bug.cgi?id=1721876
So now I use a relative PATH on OPENCV_CONFIG_INSTALL_PATH

-DOPENCV_CONFIG_INSTALL_PATH=%{_lib}/cmake/OpenCV \

or

-DOPENCV_CONFIG_INSTALL_PATH=lib64/cmake/OpenCV \

@sergiomb2 Mentioned ticket is not about pkg-config file (this issues does).
There are fresh fixes/discussions about CMake config generation and absolute/relative paths: #14925 #14963

With 4.1.0, got it functional. I found the mistake in the command provided earlier. Need to use ON, instead of YES.

OPENCV_GENERATE_PKGCONFIG=ON
....

This is correct I have tested both. When ON is used opencv4 will generate the opencv4.pc file into .../pkconfig folder.

As a side note, there are mistakes or deprecated code in books for opencv4. I struggled for days to get an example to work. Finally I got this and it works:

cd ~/opencv/samples/cpp
g++ opencv_version.cpp $(pkg-config --cflags --libs opencv4) -o show_version

Hi there.

I don't like putting -1 on already accepted (but biased) proposal, but here a wider explanation:

it would be nice if there were multiple opencv.pc files like opencv3.4.pc opencv4.pc

If one application is compatible with opencv2 -> opencv5 (if ever future master is 5 ), then it's easy enough to rely on the same opencv.pc (when using pkgconf), and not to adapt every now and then.

My point to keep using opencv.pc by default is to avoid having to adapt applications everytime the opencv.pc version changes. Because from a distro package maintainer, it's easier if everyone use the same opencv.pc.
You can see the #16902 for other comments on the topic.

I try OPENCV_GENERATE_PKGCONFIG=ON. but not work.
I try OPENCV_GENERATE_PKGCONFIG=YES. but not work.
I try -DOPENCV_GENERATE_PKGCONFIG=ON. but not work.
opencv 4.3.0
I install opencv to my local path. such as /data/home/xxx/opencv. I use make and make install. or make make install. both not work.
I give up. I will add lib and include file to makefile.

in the cmake option you need to put -DOPENCV_GENERATE_PKGCONFIG=ON
then after have performed the make "command" you will find in your build folder a folder with the name of you os (I my case "unix") with inside the .pc file

@Usernamezhx

You didn't forget the "-D" option, did you?

I have always had a space after -D as in the docs, like:
-D OPENCV_GENERATE_PKGCONFIG=ON

but writing without the space apparently works as well:
-DOPENCV_GENERATE_PKGCONFIG=ON

The following below is a quote from my install script and the cmake part definitively works for opencv 4.2.0. This quote is not a complete install script by any means. I have lots of libraries installed separately before that so you need to make a script of your own for your own purposes. Do not forget the ldconfig at the end as that finalizes some install stuff on Linux. You may also need to edit you paths in ~/.bashrc. First moving downloaded stuff to opencv folder then etc...

mv opencv-4.2.0 opencv
cd opencv
mkdir build
cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_QT=ON -D OPENCV_GENERATE_PKGCONFIG=ON -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_V4L=ON -D WITH_EIGEN=ON -D WITH_OPENGL=ON -D FORCE_VTK=ON -D WITH_TBB=ON -D WITH_XINE=ON -D BUILD_EXAMPLES=ON -D BUILD_PERF_TESTS=OFF -D ENABLE_PRECOMPILED_HEADERS=OFF .. -D INSTALL_C_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D BUILD_opencv_python3=ON -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-4.2.0/modules ..

make -j6
sudo make install
sudo ldconfig

Check where your opencv4.pc is:

First move all the way up, twice from your home with
cd ..
cd ..

Then:

sudo find -name opencv4.pc

You should find some pkgfolders with this:

sudo find -name pkgconfig

Hope this helps.

PS. The copy of cmake in my previous post must be a one single continuous line without line breaks. Just add proper line breaks if you want to split it manually to multiple lines.
Once you think you have opencv properly installed you can test it, first move to the cpp samples folder like:

cd ~/opencv/samples/cpp

Compile the opencv_version.cpp to a run file named show_my_version

g++ opencv_version.cpp $(pkg-config --cflags --libs opencv4) -o show_my_version

and run it : ./show_my_version

@dalilander yeah. it works. so amazing. thanks for your kindly reply.

I faced a similar issue after installing OpenCV 4.2.0 and could not find a way to compile a c++ program using CMakeLists.txt. I had other versions of OpenCV installed too so had to provide specific path to compiler. The pkg--configs was set and could identify opencv4 thanks to the solution posted above for building OpenCV with _-D OPENCV_GENERATE_PKGCONFIG=YES_ > Although had to export the pkg-config .pc file path to the environment variable like this:
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/home/ubuntu/opencv/opencv4/lib/pkgconfig

The usual way I compiled with OpenCV upto version 3.4.4 was cmake . -DOpenCV_DIR=~/opencv/opencv4/share/ (or /usr/local/share/OpenCV), however it didn't work with 4.2.0. Finally noticed that 4.2.0 didn't put the Config.cmake and Config-version.cmake files in the share/ directory. Instead they were put in a separate /lib/cmake/opencv4/ directory. Now I can compile all programs with cmake. -DOpenCV_DIR=(yopur opencv installation location)/opencv4/lib/cmake/opencv4 and everything works perfectly!

I also addedfind_package( OpenCV 4.2.0 REQUIRED ) in CMakeLists.txt. Not sure if this is the best way but hope it helps others!

Hello there,
I tried the suggestions above (thanks to @dalilander and @hardikparwana), but none of them worked. the installation is: Raspberry PI 4 ARMv7l, Centos 7.
OpenCV is the latest available in GitHub repository, v.4.4 https://github.com/opencv/opencv/

I compiled openCV as in the command bellow. I also tried ... =ON as in ... -D OPENCV_GENERATE_PKGCONFIG=YES

make3 -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_GENERATE_PKGCONFIG=YES -D OPENCV_EXTRA_MODULES_PATH=/usr/local/src/opencv_build/opencv_contrib/modules -D BUILD_EXAMPLES=ON ..

Then, I followed the installation steps,

make -j4 (in my case is 4)
sudo make install
sudo ln -s /usr/local/lib64/pkgconfig/opencv4.pc /usr/share/pkgconfig/
sudo ldconfig
pkg-config --modversion opencv4

then, it returns the error bellow

@Rasp build]$ pkg-config --modversion 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

Must I add opencv4.pc manually? How must I add it?

Best wishes,
I

@iuri I think you did not export the PKG_CONFIG_PATH like I proposed in my solution. You need to do it manually. I think your problem will be solved once you do it.
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/home/ubuntu/opencv/opencv4/lib/pkgconfig

Just replace the path with yours.

Exactly!
and why didn't I export it?
Because there is no such file called Config.cmake neither Config-version.cmake in the share/ or /lib directory. They don't even exist in the entire filesystem. By the way, I noticed your examples is for Ubuntu, my O.S. is Centos 7, Arch is armV7L
I ran "find" in the command line, and there was only samples within openCV directory.

[@Rasp ~]$ sudo find / -iname "Config.cmake"
/usr/local/src/opencv_build/opencv/samples/hal/c_hal/config.cmake
/usr/local/src/opencv_build/opencv/samples/hal/slow_hal/config.cmake
[@Rasp ~]$ sudo find / -iname "Config-version.cmake"
[@Rasp ~]$

Should I install pkg_config ?
https://stackoverflow.com/questions/28997618/installing-pkg-config-files-to-proper-path-on-centos-with-automake

Best wishes,
I

Hi there,
I found the answer!
Actually, I found the problem. I noticed symlink was assigned to the wrong direction

sudo ln -s /usr/local/lib64/pkgconfig/opencv4.pc /usr/share/pkgconfig/

There is no /lib64/. So, I removed that symlink, searched for any reference of opencv.pc in the filesystem, found "usr/local/lib/pkgconfig/opencv.pc" , then created a new symlink,

ln -s /usr/local/lib/pkgconfig/opencv.pc /usr/share/pkgconfig/

"pkg-config --modversion opencv" now returns 3.4.11.

It seems I've got a previous version of openCV, which I had installed from YUM pkg manager system.

I'm going to clean up that version, and start from scratch a new openCV insllation from the 4.2 source.

Best wishes,
I

Was this page helpful?
0 / 5 - 0 ratings