Robotics StackExchange | Archived questions

pkg_check_modules doesn't get the right libavcodec

I've struggled some time to make usb_cam to support mjpeg format usb camera, as libavcodec and libswscale that come with ROS somehow cannot work properly. it complains No accelerated colorspace conversion found from yuv422p to rgb24.

So I installed a new ffmpeg that enables libx264. After that, two versions of ffmpeg exist in my file system, the old one locates in /usr/lib/x86_64-linux-gnu, the new one in /usr/local/lib. In order to find the correct version, I changed two lines in the CMakeLists.txt :

pkg_check_modules(avcodec libavcodec>=56.12 REQUIRED) 

pkg_check_modules(swscale libswscale>=3.1 REQUIRED)

If I run cmake inside the usbcam directory, pkgcheckmodules can find the correct header file and libraries, however if I run catkinmake, it returns the old ones. how could pkgcheckmodules behave differently with/without ROS? Don't know what to do ...

Thanks to ahendrix! I added a few lines to print some pkgconfig-generated value

MESSAGE(STATUS "@@@@@@@@@@@@@@@@@ " ${avcodec_LIBRARIES})
MESSAGE(STATUS "@@@@@@@@@@@@@@@@@ " ${avcodec_LIBRARY_DIRS})
MESSAGE(STATUS "@@@@@@@@@@@@@@@@@ " ${avcodec_LDFLAGS})
MESSAGE(STATUS "@@@@@@@@@@@@@@@@@ " ${avcodec_INCLUDE_DIRS})
MESSAGE(STATUS "@@@@@@@@@@@@@@@@@ " ${avcodec_CFLAGS})
MESSAGE(STATUS "@@@@@@@@@@@@@@@@@ " ${avcodec_VERSION})
MESSAGE(STATUS "@@@@@@@@@@@@@@@@@ " ${avcodec_PREFIX})
MESSAGE(STATUS "@@@@@@@@@@@@@@@@@ " ${avcodec_INCLUDEDIR})
MESSAGE(STATUS "@@@@@@@@@@@@@@@@@ " ${avcodec_LIBDIR})

After I delete build/ and devel/ and run catkin_make as ahendrix suggestes, cmake output message shows it found the right version

-- checking for module 'libavcodec'
--   found libavcodec, version 56.13.100
-- checking for module 'libswscale'
--   found libswscale, version 3.1.101
-- @@@@@@@@@@@@@@@@@ avcodec
-- @@@@@@@@@@@@@@@@@ /usr/local/lib
-- @@@@@@@@@@@@@@@@@ -L/usr/local/lib-lavcodec
-- @@@@@@@@@@@@@@@@@ /usr/local/include
-- @@@@@@@@@@@@@@@@@ -I/usr/local/include
-- @@@@@@@@@@@@@@@@@ 56.13.100
-- @@@@@@@@@@@@@@@@@ /usr/local
-- @@@@@@@@@@@@@@@@@ /usr/local/include
-- @@@@@@@@@@@@@@@@@ /usr/local/lib

however, when ran this node "rosrun usbcam usbcamnode _pixelformat:=mjpeg", it just end with segment fault. But if write the CMakeLists.tst like

 #find_package(PkgConfig REQUIRED)
 #pkg_check_modules(avcodec libavcodec REQUIRED)
 #pkg_check_modules(swscale libswscale REQUIRED)

 set(avcodec_INCLUDE_DIRS /usr/local/include/libavcodec) 

 set(swscale_INCLUDE_DIRS /usr/local/include/libswscale)

 set(avcodec_LIBRARIES /usr/local/lib/libavcodec.so.56)

 set(swscale_LIBRARIES /usr/local/lib/libswscale.so.3)

usb_cam turns to work. So I wonder what happens to make such difference.

Asked by taogashi on 2014-11-22 23:12:52 UTC

Comments

Have you tried deleting the build and devel folders in your catkin workspace and rebuilding them from scratch? It's possible that cmake is caching the previous pkg_check results.

Asked by ahendrix on 2014-11-23 00:28:55 UTC

Thanks ahendrix! I've tried and updated my question.

Asked by taogashi on 2014-11-23 03:30:02 UTC

Answers