ubuntu编译报错(opencv)

报错1:

报错类似这种:

/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFReadScanline@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFReadRGBAStrip@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFSetErrorHandler@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFReadEncodedStrip@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFReadRGBATile@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFClientOpen@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFSetField@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFScanlineSize@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFSetWarningHandler@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFWriteDirectory@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFWriteScanline@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFRGBAImageOK@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFReadDirectory@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFIsTiled@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFReadEncodedTile@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFClose@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFWriteEncodedStrip@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFGetField@LIBTIFF_4.0'
/usr/bin/ld: /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so: undefined reference to `TIFFOpen@LIBTIFF_4.0'

解决方法:

sudo apt-get install libtiff5-dev

安装完之后,再次编译。如果还是报错,对报错的opencv库,执行ldd。如:

ldd /home/miuney/Project/NFIP/lib/opencv4.10_x86/libopencv_imgcodecs.so

可以看到我的libtiff库指向的是: /home/miuney/anaconda3/lib/libtiff.so.5,实际上这个库的并不是我们想要的tiff库版本,因为安装了conda的原因,导致存在多个tiff版本,链接器找错了(至于为什么找错,可以看看我的另一篇文章,对连接器的工作逻辑,说的很清楚。linux加载动态库那些事(C/C++))。我们用搜索一下刚才装的tiff库放哪了。locate libtiff.so.5

一般apt install安装的库都是放下/lib /usr/lib下边,所以我们真正想要的库应该是:/usr/lib/x86_64-linux-gnu/libtiff.so.5 这个。(至于so      so.5    so.5.7.0的关系,就是so指向了so.5又指向了so.5.7.0仅此而已,软连接)

找到问题原因那就好解决了,我们只需要让依赖指向我们想要的那个就行了。为了不影响其他软件程序,一个简单的办法,我们让原本指向anaconda下的软连接,强制指向正确的。

1、先备份:mv  /home/miuney/anaconda3/lib/libtiff.so.5  /home/miuney/anaconda3/lib/libtiff.so.5_bak

2、创建软连接,指向正确库:ln  -s   /usr/lib/x86_64-linux-gnu/libtiff.so.5 /home/miuney/anaconda3/lib/libtiff.so.5

重新编译,应该是ok了。中间涉及到的路径,根据自己的情况做修改。

报错2:

/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0: undefined reference to `g_log_set_debug_enabled'

问题原因就是,在使用opencv库的时候,opencv编译时依赖的基础库,与当前使用时,基础库的版本出现了不一致导致。

解决方法:在当前环境下,重新编译opencv库即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值