opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
75.95k stars 55.62k forks source link

4.0.0 does not produce pkgconfig file #13154

Closed ekudritski closed 8 months ago

ekudritski commented 5 years ago
System information (version)
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

alalek commented 5 years ago

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:


In general, package maintainers should provide own .pc file validated for provided OpenCV build configuration. Perhaps written from the scratch.

dustsigns commented 5 years ago

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?

ekudritski commented 5 years ago

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.

codenoid commented 5 years ago

CMakeLists.txt :

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

it doesn't work

pathouse commented 5 years ago

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

rdp commented 5 years ago

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

rdp commented 5 years ago

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

Favi0 commented 5 years ago

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?

rdp commented 5 years ago

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 .

tsengia commented 5 years ago

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.

Adhders commented 5 years ago
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

jhgfkdj commented 5 years ago

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 ...

UberEclectic commented 5 years ago

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?

Kevin-Mok commented 5 years ago

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.

corbelr commented 5 years ago

@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

un-lock-me commented 5 years ago

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.

un-lock-me commented 5 years ago

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!

rdp commented 5 years ago

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. :| … <#m9070919798374828714> 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 .

sergiomb2 commented 4 years ago

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

prabindh commented 4 years ago

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 ..

prabindh commented 4 years ago

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

sergiomb2 commented 4 years ago

useful if not using CMake in projects that use OpenCV

don't say that is deprecated [1] please

[1] 73f65b1

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

ytm95 commented 4 years ago

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

sergiomb2 commented 4 years ago

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 \
mkschreder commented 4 years ago

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

yizongk commented 4 years ago

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.

sergiomb2 commented 4 years ago

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 \
alalek commented 4 years ago

@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

tordals commented 4 years ago

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

kwizart commented 4 years ago

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.

Usernamezhx commented 4 years ago

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.

thewoz commented 4 years ago

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

tordals commented 4 years ago

@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.

tordals commented 4 years ago

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

Usernamezhx commented 4 years ago

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

hardikparwana commented 3 years ago

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!

iuri commented 3 years ago

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

hardikparwana commented 3 years ago

@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.

iuri commented 3 years ago

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

qonteo commented 3 years ago

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

typelogic commented 2 years ago

Using well-known system paths such as /usr/lib/ or /usr/local/lib etc as destination dirs when compiling/installing anything from source smells fishy to me as its collision course is imminent with system updates. I have my destination dirs for anything I manually compile and install set to /opt/my/opencv/4.0.0/, for example. And leave the system stuff alone.