命令如下:
wget https://github.com/Kitware/CMake/releases/download/v3.22.1/cmake-3.22.1.tar.gz tar -xzvf cmake-3.22.1.tar.gz && cd cmake-3.22.1/ && ./bootstrap && gmake && gmake install
設置環境PATH,修改~/.bashrc,添加 export PATH="$PATH:/usr/local/bin"
並重新更新環境變量即可
source ~/.bashrc [root@bogon cmake]#cmake -version version 3.22.1 suite maintained and supported by Kitware (kitware.com/cmake).
安裝OK
測試:
#include <iostream> int main(int argc, char *argv[]) { std::cout << "Hello CMake!" << std::endl; return 0; }
CMakeLists.txt
# Set the minimum version of CMake that can be used # To find the cmake version run # $ cmake --version cmake_minimum_required(VERSION 3.5) # Set the project name project (hello_cmake) # Add an executable add_executable(hello_cmake main.cpp)
執行命令
mkdir build && cd build && cmake ../ && make
Link ok。Enjoy
示例:
https://github.com/ttroy50/cmake-examples