Bug 82245

Summary: --libs-only-l does not contain anything even though --libs does
Product: pkg-config Reporter: andrea.tagliasacchi
Component: srcAssignee: Dan Nicholson <dbn.lists>
Status: RESOLVED NOTOURBUG QA Contact:
Severity: critical    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: Mac OS X (All)   
Whiteboard:
i915 platform: i915 features:

Description andrea.tagliasacchi 2014-08-06 11:23:57 UTC
In cmake I can use PkgConfig to import opencv:

#--- OpenCV (with pkgconfig)
find_package(PkgConfig REQUIRED)
pkg_check_modules(OPENCV REQUIRED opencv)
list(APPEND LIBRARIES ${OPENCV_LIBRARIES})
message(STATUS LIBS ${OPENCV_VERSION})
include_directories(${OPENCV_INCLUDE_DIRS})

However, I noticed OPENCV_LIBRARIES was empty!!
I checked FindPkgConfig.cmake and noticed the following:

pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LIBRARIES           "(^| )-l" --libs-only-l )
pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LDFLAGS             ""        --libs )

So I went and tried...

~/Developer/homebrew: pkg-config --libs opencv
/usr/local/Cellar/opencv/2.4.9/lib/libopencv_calib3d.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_contrib.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_core.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_features2d.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_flann.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_gpu.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_highgui.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_imgproc.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_legacy.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_ml.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_nonfree.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_objdetect.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_ocl.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_photo.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_stitching.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_superres.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_ts.a /usr/local/Cellar/opencv/2.4.9/lib/libopencv_video.dylib /usr/local/Cellar/opencv/2.4.9/lib/libopencv_videostab.dylib 
~/Developer/homebrew: pkg-config --libs-only-l opencv

~/Developer/homebrew:  

As you can see --libs-only-l is completely empty!
If this is a problem with opencv.pc please let me know.
Comment 1 Dan Nicholson 2014-09-27 23:26:06 UTC
Sorry for the slow reply. Could you show the contents of opencv.pc?
Comment 2 andrea.tagliasacchi 2014-09-28 10:10:28 UTC
~: cat /usr/local/lib/pkgconfig/opencv.pc
# Package Information for pkg-config

prefix=/usr/local/Cellar/opencv/2.4.9
exec_prefix=${prefix}
libdir=
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 2.4.9
Libs:  ${exec_prefix}/lib/libopencv_calib3d.dylib ${exec_prefix}/lib/libopencv_contrib.dylib ${exec_prefix}/lib/libopencv_core.dylib ${exec_prefix}/lib/libopencv_features2d.dylib ${exec_prefix}/lib/libopencv_flann.dylib ${exec_prefix}/lib/libopencv_gpu.dylib ${exec_prefix}/lib/libopencv_highgui.dylib ${exec_prefix}/lib/libopencv_imgproc.dylib ${exec_prefix}/lib/libopencv_legacy.dylib ${exec_prefix}/lib/libopencv_ml.dylib ${exec_prefix}/lib/libopencv_nonfree.dylib ${exec_prefix}/lib/libopencv_objdetect.dylib ${exec_prefix}/lib/libopencv_ocl.dylib ${exec_prefix}/lib/libopencv_photo.dylib ${exec_prefix}/lib/libopencv_stitching.dylib ${exec_prefix}/lib/libopencv_superres.dylib ${exec_prefix}/lib/libopencv_ts.a ${exec_prefix}/lib/libopencv_video.dylib ${exec_prefix}/lib/libopencv_videostab.dylib
Cflags: -I${includedir_old} -I${includedir_new}
~:
Comment 3 Dan Nicholson 2014-11-11 21:19:11 UTC
Oh, that's a tricky one. You're not actually specifying -l anywhere, so pkg-config thinks it's doing the right thing. It might be possible to fix this, but the best thing to do would be to fix the opencv pkg-config file to act like a standard pc file.

prefix=/usr/local/Cellar/opencv/2.4.9
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 2.4.9
Libs: -L${exec_prefix}/lib -lopencv_calib3d -lopencv_contrib -lopencv_core ...
Cflags: -I${includedir_old} -I${includedir_new}
Comment 4 Dan Nicholson 2014-11-12 15:27:56 UTC
Actually, now that I think about this some more, I think the bug is in cmake's FindPkgConfig. They're assuming that the only way to specify libraries is through -l. That's a reasonable assumption, but not technically correct. It's entirely reasonable to specify an absolute path to a library.

I think this would be fixed if the LIBRARIES call was made as --libs-only-l --libs-only-other. The other flags will contain all of your direct opencv*.dylib libraries. That might introduce other issues in cmake's pkg-config handling, but I don't believe this is pkg-config's bug. This is either cmake's bug (assuming -l contains all the libraries) or opencv's bug (shipping a non-standard pkg-config file).

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.