从GitHub下载opencv2.4.13,然后解压:
wget https://github.com/Itseez/opencv/archive/2.4.13.zip
unzip 2.4.13.zip
然后进入到OpenCV的目录下,开始编译安装OpenCV2.4.13的源码。
cd opencv-2.4.13
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local …
make
sudo make install
常见问题,及解决方式
常见问题1:
CMake Warning at cmake/OpenCVPackaging.cmake:23 (message):
CPACK_PACKAGE_VERSION does not match version provided by version.hpp
header!
Call Stack (most recent call first):
CMakeLists.txt:1105 (include)
解决方式:
打开OpenCV-2,4,13下的CMakeList.txt文件。
找到这里
find_host_program(GIT_EXECUTABLE NAMES ${git_names} PATH_SUFFIXES Git/cmd Git/bin DOC “git command line client”)
mark_as_advanced(GIT_EXECUTABLE)
if(GIT_EXECUTABLE)
execute_process(COMMAND {OpenCV_SOURCE_DIR}"
OUTPUT_VARIABLE OPENCV_VCSVERSION
RESULT_VARIABLE GIT_RESULT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_RESULT EQUAL 0)
set(OPENCV_VCSVERSION “unknown”)
endif()
else()
We don’t have git:
set(OPENCV_VCSVERSION “unknown”)
endif()
把这两句“set(OPENCV_VCSVERSION “unknown”)”注释掉,
分别加上这句“set(OPENCV_VCSVERSION “2.4.13”)”
点击保存,即可。
常见问题2:
CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:85 (list):
list GET given empty list
Call Stack (most recent call first):
CMakeLists.txt:89 (include)
CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:86 (list):
list GET given empty list
Call Stack (most recent call first):
CMakeLists.txt:89 (include)
CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:89 (math):
math cannot parse the expression: "*100 + ": syntax error, unexpected
exp_TIMES, expecting exp_PLUS or exp_MINUS or exp_OPENPARENT or exp_NUMBER
(1)
Call Stack (most recent call first):
CMakeLists.txt:89 (include)
解决方式:
打开OpenCV-2.4.13下的cmake文件夹下的OpenCVDetectopiler.cmake文件
大概在中间位置,修改第67行"-dumpversion" 为 “-dumpfullversion”
原因是GCC版本太高了(>6),无法获取所有版本的编译器。
常见问题3:
/usr/include/c++/7/cstdlib:75:15: fatal error: stdlib.h: 没有那个文件或目录
#include_next <stdlib.h>
^~~~~~~~~~
compilation terminated.
解决方案:
在执行语句“cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local … ”时,改为“cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local … -DENABLE_PRECOMPILED_HEADERS=OFF
”,然后再执行make.
参考:
https://blog.csdn.net/mysea2004/article/details/72566730.
https://github.com/opencv/opencv/pull/9430/files.
https://blog.csdn.net/Stackingrule/article/details/90146828.