常见问题分析解决
使用过程遇到的问题
(1)undefined reference to `TIFFXXX@LIBTIFF_4.0’
错误提示
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFReadDirectory@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFWriteEncodedStrip@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFIsTiled@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFOpen@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFReadEncodedStrip@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFSetField@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFWriteScanline@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFGetField@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFScanlineSize@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFNumberOfStrips@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFSetWarningHandler@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFSetErrorHandler@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFReadEncodedTile@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFReadRGBATile@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.3.0: undefined reference to 'TIFFClose@LIBTIFF_4.0'
解决步骤:
1.检查是否安装libtiff4-dev
2.尝试使用sudo make
3.重装opencv,在cmake时加入参数-DBUILD_TIFF=ON
(2)提示安装libgtk2.0-dev
错误信息
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow, file /home/jellal/Downloads/opencv-3.3.0/modules/highgui/src/window.cpp, line 587
terminate called after throwing an instance of 'cv::Exception'
what(): /home/jellal/Downloads/opencv-3.3.0/modules/highgui/src/window.cpp:587: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvNamedWindow
解决过程:
1.直接sudo apt install libgtk2.0-dev
提示需要若干依赖, but is not going to install.
2.尝试根据安装所需的依赖,然后成功安装libgtk2.0-dev
3.尝试运行程序,提示缺少libpng16.so.16
4.安装libpng16-dev
5.运行仍然出现上述错误提示,并且可以再次安装libgtk2.0-dev
6.发现是依赖问题,用aptitude安装libgtk2.0-dev,提示需要移除libpng16
小结:libgtk2.0-dev和libpng16-dev冲突
7.利用aptitude安装libgtk2.0-dev后,去下载libpng16的rpm包,利用alien转换为deb包后安装,仍然提示缺少libpng16.so.16
8.sudo updatedb后locate libpng16.so.16,找到目录后,在/etc/ld.so.conf中或者在该文件include的conf文件中加入该目录路径,运行后仍出现最初错误提示
根据相关资料所述,需要在opencv安装前安装gtk2.0
9.故此时重新安装opencv,运行仍然出现最初错误提示
10. sudo apt install libgnomeui-dev ,然后再次重新安装opencv,问题解决
解决过程:
- sudo apt install libgnomeui-dev
- 重新安装opencv
使用过程中的现象分析
CMakeLists.txt
find_package的作用分析
1.使用过程中发现message可以输出OpenCV_VERSION、OpenCV_LIBS和OpenCV_INCLUDE_DIRS等变量
2.echo测试后发现并非环境变量
3.将message置于find_package之前无输出
小结:find_package作用,一是得到相关变量,二是确定引用的头文件和链接的库目录等,实际作用有待分析