刚装好的系统Ubuntu20.04上,想编译安装一下Opencv455,会出现很多的"Could NOT find"报错,有些是完全是可以忽略的,有些用户可能会根据自己的需要安装,我这里列一下自己想安装的一些包。
通用的解决办法
首先,你要如何找到那些你想安装的文件包呢?一般我们可以通过
apt-cache search libjpeg
或
apt search libjpeg
来查找含有libjpeg关键字的包,然后根据描述看是否是我们所需要的包,
查找完之后通过sudo apt install 这样的指令安装。注意安装完之后可能要重启terminal才会重读取相关路径参数。
如果你已经知道安装路径,但你的编译器程序老是找不到,那就试试在~/.bashrc中添加下面的语句导出路径,
export LD_LIBRARY_PATH=/usr/local/zlib/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=/usr/local/zlib/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/usr/local/zlib/include:$CPLUS_INCLUDE_PATH
找不到编译器: No CMAKE_CXX_COMPILER could be found
CMake Error at CMakeLists.txt:113 (enable_language):
No CMAKE_CXX_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:113 (enable_language):
No CMAKE_C_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
解决办法,
sudo apt install g++
找不到依赖包:Could NOT find ZLIB等文件包
首先要说明,对于OpenCV而言,这些包的安装不是必须的,当Opencv在路径中找不到OpenJPEG文件包的时候,就会去下载这些第三方包重新编译,然后生成想要的静态或动态库。当然你也可以自己去下载源码后再编译安装。在能安装使用成功的情况下,我一般会选择直接安装。
Looking for ccache - not found
Cleaning INTERNAL cached variable: ZLIB_LIBRARY
Cleaning INTERNAL cached variable: ZLIB_INCLUDE_DIR
Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR) (Required is at least version "1.2.3")
Cleaning INTERNAL cached variable: JPEG_LIBRARY
Cleaning INTERNAL cached variable: JPEG_INCLUDE_DIR
Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR)
libjpeg-turbo: VERSION = 2.1.2, BUILD = opencv-4.5.5-libjpeg-turbo
Cleaning INTERNAL cached variable: TIFF_LIBRARY
Cleaning INTERNAL cached variable: TIFF_INCLUDE_DIR
Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR)
Cleaning INTERNAL cached variable: WEBP_LIBRARY
Cleaning INTERNAL cached variable: WEBP_INCLUDE_DIR
Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
OpenJPEG: VERSION = 2.4.0, BUILD = opencv-4.5.5-openjp2-2.4.0
OpenJPEG libraries will be built from sources: libopenjp2 (version "2.4.0")
Cleaning INTERNAL cached variable: PNG_LIBRARY
Cleaning INTERNAL cached variable: PNG_INCLUDE_DIR
Could NOT find PNG (missing: PNG_LIBRARY PNG_PNG_INCLUDE_DIR)
libva: missing va.h header (VA_INCLUDE_DIR)
这里面缺少好几个包:
zlib
libjpeg
libtiff
openJPEG
解决办法,
sudo apt install zlib1g-dev
sudo apt install libjpeg8-dev (会同时安装libjpeg-turbo8-dev)
sudo apt install libtiff5-dev (会同时安装libtiff-dev)
说明:我没有选择安装lilbopenjp (openJPEG),因为我发现,安装这个包的时候,
sudo apt install libopenjp2-7-dev
会出现更多的报错,例如
The imported target "openjp2_static" references the file "/usr/lib/x86_64-linux-gnu/libopenjp2.a" but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/x86_64-linux-gnu/openjpeg-2.1/OpenJPEGTargets.cmake"
but not all the files it references.
The imported target "openjpip" references the file
"/usr/lib/x86_64-linux-gnu/libopenjpip.so.2.3.1"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/x86_64-linux-gnu/openjpeg-2.1/OpenJPEGTargets.cmake"
but not all the files it references.
The imported target "openjpip_server" references the file
"/usr/lib/x86_64-linux-gnu/libopenjpip_server.a"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/x86_64-linux-gnu/openjpeg-2.1/OpenJPEGTargets.cmake"
but not all the files it references.
The imported target "opj_decompress" references the file
"/usr/bin/opj_decompress"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/x86_64-linux-gnu/openjpeg-2.1/OpenJPEGTargets.cmake"
but not all the files it references.
The imported target "opj_compress" references the file
"/usr/bin/opj_compress"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/x86_64-linux-gnu/openjpeg-2.1/OpenJPEGTargets.cmake"
but not all the files it references.
The imported target "opj_dump" references the file
"/usr/bin/opj_dump"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/x86_64-linux-gnu/openjpeg-2.1/OpenJPEGTargets.cmake"
but not all the files it references.
The imported target "opj_jpip_addxml" references the file
"/usr/bin/opj_jpip_addxml"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/x86_64-linux-gnu/openjpeg-2.1/OpenJPEGTargets.cmake"
but not all the files it references.
The imported target "opj_server" references the file
"/usr/bin/opj_server"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/x86_64-linux-gnu/openjpeg-2.1/OpenJPEGTargets.cmake"
but not all the files it references.
The imported target "opj_dec_server" references the file
"/usr/bin/opj_dec_server"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/x86_64-linux-gnu/openjpeg-2.1/OpenJPEGTargets.cmake"
but not all the files it references.
The imported target "opj_jpip_transcode" references the file
"/usr/bin/opj_jpip_transcode"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/x86_64-linux-gnu/openjpeg-2.1/OpenJPEGTargets.cmake"
but not all the files it references.
The imported target "opj_jpip_test" references the file
"/usr/bin/opj_jpip_test"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/x86_64-linux-gnu/openjpeg-2.1/OpenJPEGTargets.cmake"
but not all the files it references.
最主要的,我不知道去哪里找这个包:libopenjp2.a。所以我重新configure了一下opencv,
Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
OpenJPEG: VERSION = 2.4.0, BUILD = opencv-4.5.5-openjp2-2.4.0
OpenJPEG libraries will be built from sources: libopenjp2 (version "2.4.0")
这样,当Opencv在路径中找不到OpenJPEG文件包的时候,就会去下载这些第三方包重新编译。
本文结束