pkg_check_modules doesn't get the right libavcodec

asked 2014-11-22 22:12:52 -0500

taogashi gravatar image

updated 2014-11-23 15:34:22 -0500

ahendrix gravatar image

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 usb_cam directory, pkg_check_modules can find the correct header file and libraries, however if I run catkin_make, it returns the old ones. how could pkg_check_modules 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 usb_cam usb_cam_node _pixel_format:=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.

edit retag flag offensive close merge delete

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.

ahendrix gravatar image ahendrix  ( 2014-11-22 23:28:55 -0500 )edit

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

taogashi gravatar image taogashi  ( 2014-11-23 02:30:02 -0500 )edit