• 编译报错:undefined reference to `TIFFReadDirectory@LIBTIFF_4.0‘解决方法


    一、问题描述

    自己的环境:Ubuntu18.04。

    自己编译C++程序的时候,遇到如下报错:

    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFReadDirectory@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFLastDirectory@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFWriteEncodedStrip@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFIsTiled@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFSwabArrayOfShort@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFIsByteSwapped@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFFlushData@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFFreeDirectory@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFScanlineSize@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFWriteEncodedTile@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFWriteBufferSetup@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFTileSize@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFRGBAImageOK@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFClose@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFWriteRawStrip@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFSetTagExtender@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFGetFieldDefaulted@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFSwabArrayOfLong@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFTileSize64@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFReadRGBATileExt@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFStripSize@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFMergeFieldInfo@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFSetWarningHandler@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFGetConfiguredCODECs@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libgeotiff.so.2: undefined reference to `_TIFFmalloc@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libgeotiff.so.2: undefined reference to `_TIFFmemcpy@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFClientdata@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libgeotiff.so.2: undefined reference to `_TIFFrealloc@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libgeotiff.so.2: undefined reference to `_TIFFmemset@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFReadRGBAStripExt@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFWriteCheck@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFSetWriteOffset@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFDefaultStripSize@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFScanlineSize64@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFIsBigEndian@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libpoppler.so.73: undefined reference to `TIFFFdOpen@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFWriteScanline@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `_TIFFfree@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFSwabLong@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFGetField@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFSwabShort@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFNumberOfStrips@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFWriteDirectory@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFReadEncodedTile@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFReadRGBATile@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libgeotiff.so.2: undefined reference to `TIFFClientOpen@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFFlush@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFErrorExt@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFNumberOfDirectories@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFWriteRawTile@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFStripSize64@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFCreateDirectory@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFOpen@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFSwabArrayOfDouble@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFSetSubDirectory@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFUnlinkDirectory@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFReadEncodedStrip@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFSetField@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFCurrentDirOffset@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFIsCODECConfigured@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFUnsetField@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFDataWidth@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFRewriteDirectory@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFGetSizeProc@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFSetErrorHandler@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFSetDirectory@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFReadScanline@LIBTIFF_4.0'
    //usr/lib/libgdal.so.20: undefined reference to `TIFFNumberOfTiles@LIBTIFF_4.0'
    /usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0: undefined reference to `TIFFReadRGBAStrip@LIBTIFF_4.0'
    collect2: error: ld returned 1 exit status
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70

    二、出现原因与解决方法

    出现原因主要是系统中存在的 tiff 版本与编译需要的版本不一致导致的。出现上述报错undefined reference to TIFFReadDirectory@LIBTIFF_4.0 是因为编译程序需要的是 tiff-4.0 版本,但是系统内的不是这个版本。
    安装方法:
    libtiff官网 下载对应的安装包 tiff-4.0.10.zip,(tiff-4.0.x.zip 都可以),解压之后,然后编译安装:

    cd tiff-4.0.10/
    mkdir cmake-build
    cd cmake-build/
    cmake ..
    make
    sudo make install
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    然后再次编译,就可以编译通过了。

    注意:
    libtiff 是应该可以通过sudo apt-get install libtiff4-dev进行安装,但是运行该命令后,不能找到安装包,而只能运行 sudo apt-get install libtiff5-dev 才能成功,但是这样安装的是libtiff5,这样安装后并不能解决本博客遇到的问题。

    参考链接

    [1] 以道御术. 在ubuntu下安装opencv和PCL时 undefined reference to `TIFFReadDirectory@LIBTIFF_4.0 [EB/OL]. https://blog.csdn.net/u013372308/article/details/100168651, 2019-08-31/2022-11-06.
    [2] 蒲公英云. tesseract-4.0.0源码编译安装 [EB/OL]. https://dandelioncloud.cn/article/details/1478780643671887873, 2022-01-06/2022-11-06.

  • 相关阅读:
    CSDN---Markdown编辑器:基本语法知识
    Linux中常见的问题
    环形链表,如何用快慢指针跑出迷宫
    『手撕Vue-CLI』拷贝模板
    利用excel批量修改图片文件名
    ISYSTEM调试实践12-软件运行时间的优化
    第6章:应用层
    20-指针-2
    bootstrap练习
    【C++天梯计划】1.4 排列组合(Permutation and Combination)
  • 原文地址:https://blog.csdn.net/qq_39779233/article/details/127718188