编译报错: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

二、出现原因与解决方法

出现原因主要是系统中存在的 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

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

注意:
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.

### 解决编译或链接时遇到的 `undefined reference to 'TIFFOpen@LIBTIFF_4.0'` 错误 当遇到此类错误时,通常是因为系统中的 libtiff 库版本与项目所需版本不符。具体来说,编译器找不到所需的 `TIFFOpen` 函数定义。 #### 方法一:确认并更新 libtiff 版本 确保当前使用的 libtiff 版本为 4.0 或更高版本。如果现有版本较低,则需下载对应版本源码重新编译安装: ```bash wget https://download.osgeo.org/libtiff/tiff-4.0.10.zip unzip tiff-4.0.10.zip cd tiff-4.0.10/ mkdir cmake-build && cd cmake-build/ cmake .. make sudo make install ``` 此过程会覆盖旧版库文件,使新版本生效[^1]。 #### 方法二:调整 CMakeLists.txt 文件配置 对于基于 CMake 的构建系统,在项目的 `CMakeLists.txt` 中显式指定 libtiff 路径及其版本号可有效解决问题。例如添加如下指令: ```cmake find_package(TIFF REQUIRED) include_directories(${TIFF_INCLUDE_DIRS}) target_link_libraries(your_target_name ${TIFF_LIBRARIES}) ``` 这有助于确保正确链接到目标版本的 libtiff 库[^2]。 #### 方法三:检查环境变量设置 有时 Anaconda 环境可能干扰默认路径下的依赖查找。建议临时移除 Conda 相关环境变量后再尝试编译操作: ```bash unset LD_LIBRARY_PATH unset LIBRARY_PATH ``` 执行以上命令后重试编译流程,观察是否仍存在相同问题[^4]。 通过上述三种方式之一或多者组合应用,应能妥善处理因 libtiff 版本差异引发的未解析符号引用错误。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值