ros编译时与opencv发生冲突的解决办法 opencv_imgcodecs3.so.3.3.1: undefined reference to `TIFFReadDirectory@LIBTIFF

在编译ros项目的时候,遇到下面的错误:

[ 38%] Building CXX object cube_slam/detect_3d_cuboid/CMakeFiles/detect_3d_cuboid.dir/src/matrix_utils.cpp.o
[ 40%] Linking CXX executable /home/fuhong/cubeslam_ws/devel/lib/tictoc_profiler/tictoc_profiler_example
[ 40%] Built target tictoc_profiler_example
[ 42%] Linking CXX executable /home/fuhong/cubeslam_ws/devel/lib/line_lbd/linelbd_detect_node
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFReadDirectory@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFWriteEncodedStrip@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFIsTiled@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFOpen@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFReadEncodedStrip@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFSetField@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFWriteScanline@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFGetField@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFScanlineSize@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFNumberOfStrips@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFSetWarningHandler@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFSetErrorHandler@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFReadEncodedTile@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFReadRGBATile@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFClose@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFRGBAImageOK@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFClientOpen@LIBTIFF_4.0’未定义的引用
/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1:对‘TIFFReadRGBAStrip@LIBTIFF_4.0’未定义的引用
collect2: error: ld returned 1 exit status
cube_slam/line_lbd/CMakeFiles/linelbd_detect_node.dir/build.make:149: recipe for target '/home/fuhong/cubeslam_ws/devel/lib/line_lbd/linelbd_detect_node' failed
make[2]: *** [/home/fuhong/cubeslam_ws/devel/lib/line_lbd/linelbd_detect_node] Error 1
CMakeFiles/Makefile2:598: recipe for target 'cube_slam/line_lbd/CMakeFiles/linelbd_detect_node.dir/all' failed
make[1]: *** [cube_slam/line_lbd/CMakeFiles/linelbd_detect_node.dir/all] Error 2
make[1]: *** 正在等待未完成的任务....
[ 44%] Linking CXX shared library /home/fuhong/cubeslam_ws/devel/lib/libdetect_3d_cuboid.so
[ 44%] Built target detect_3d_cuboid
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j8 -l8" failed

猜测应该是ros里面的opencv和自己安装的opencv发生了冲突,解决办法:

ldd /opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1

从输出里面找到libtiff相关的信息,例如我的是:

libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f81bc0e7000)

然后修改所有的CMakeList.txt文件,将/usr/lib/x86_64-linux-gnu/libtiff.so.5 添加到链接库里面去

target_link_libraries(${PROJECT_NAME}_lib
  	...
    /usr/lib/x86_64-linux-gnu/libtiff.so.5  
  )

重新编译即可。

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值