cmake時報錯:
CMake 3.8 or higher is required. You are running version 3.5.1
提示目前的cmake版本過低。
安裝步驟:
1. 查看當前cmake版本:
cmake -version
2. 卸載當前cmake:(如果安裝了ROS跳過此步)
sudo apt remove cmake
3. 下載cmake:
可直接從cmake官網下載新版本,也可執行如下語句:
wget http://www.cmake.org/files/v3.16/cmake-3.16.6.tar.gz
我這里下載的是cmake-3.16.6版本。
或是去文件庫下載:https://cmake.org/files/v3.16/
備注:官網給出兩種版本,一種是Source版的,另一種是Binary distributions里面的Linux x86_64,這是已經編譯好的可執行版,直接拿來用的,只需要建立軟連接即可,通過建立軟鏈接調用Cmake-gui來使用cmake。
我這里下載的是以.tar.gz結尾的,source版的。
4. 解壓與安裝:
tar xf cmake-3.16.6.tar.gz #解壓,也可以右鍵直接提取出來 cd cmake-3.16.6
sudo apt-get install build-essential
去文件夾看,如果有鎖說明有權限設置,返回cmake-3.16.6的上層目錄,修改文件權限(沒有鎖就不用執行這句)
sudo chmod -R 777 cmake-3.16.6
./bootstrap
此步若有報錯,看下面的遇到錯誤的解決辦法。
make
make install
驗證:
cmake --version
遇到錯誤的解決辦法:
錯誤1:運行./bootstrap時出現報錯:
-- Looking for gethostname -- Looking for gethostname - found -- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR) CMake Error at Utilities/cmcurl/CMakeLists.txt:454 (message): Could not find OpenSSL. Install an OpenSSL development package or configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL. -- Configuring incomplete, errors occurred! See also "/home/whlg/cmake-3.16.6/CMakeFiles/CMakeOutput.log". See also "/home/whlg/cmake-3.16.6/CMakeFiles/CMakeError.log". --------------------------------------------- Error when bootstrapping CMake: Problem while running initial CMake ---------------------------------------------
提示找不到OpenSSL,查看錯誤日志,缺少軟件包。
解決方案:
sudo apt-get install libssl-dev
再運行
./bootstrap
錯誤2:make install時出現報錯:
[100%] Built target foo Install the project... -- Install configuration: "" CMake Error at Source/kwsys/cmake_install.cmake:41 (file): file cannot create directory: /usr/local/doc/cmake-3.16/cmsys. Maybe need administrative privileges. Call Stack (most recent call first): cmake_install.cmake:42 (include) Makefile:76: recipe for target 'install' failed make: *** [install] Error 1
解決方案:
sudo make install
錯誤3:執行cmake --version時提示沒有那個文件或目錄:
bash: /usr/bin/cmake: 沒有那個文件或目錄
解決方案:
使用which cmake查找cmake的安裝路徑,默認是在/usr/local/bin/cmake,而系統會默認去/usr/bin中去尋找。
做一個鏈接即可:
ln -s /usr/local/bin/cmake /usr/bin
提示沒有權限的話加上sudo。
參考鏈接:
How to upgrade cmake in Ubuntu [duplicate]
Ubuntu學習心得——安裝篇——CMake舊版的卸載與新版的安裝(防踩坑+兩種安裝產生的效果)