Installing CMake {安装 CMake}
- [1. `CMake Error at CMakeLists.txt:1 (cmake_minimum_required): CMake 3.22 or higher is required. You are running version 3.16.3`](#1.
CMake Error at CMakeLists.txt:1 (cmake_minimum_required): CMake 3.22 or higher is required. You are running version 3.16.3
) - [2. `conda install cmake`](#2.
conda install cmake
) - [3. Installing CMake](#3. Installing CMake)
- References
Installing CMake
https://cliutils.gitlab.io/modern-cmake/chapters/intro/installing.html
https://modern-cmake-cn.github.io/Modern-CMake-zh_CN/chapters/intro/installing.html
1. CMake Error at CMakeLists.txt:1 (cmake_minimum_required): CMake 3.22 or higher is required. You are running version 3.16.3
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ ls
CMakeLists.txt cmake-build-debug main.cpp
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ cat main.cpp
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
project(yongqiang)
set(CMAKE_CXX_STANDARD 14)
add_executable(yongqiang main.cpp)
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ mkdir build
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ cd build/
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ cmake ..
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
CMake 3.22 or higher is required. You are running version 3.16.3
-- Configuring incomplete, errors occurred!
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$
2. conda install cmake
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ cmake --version
cmake version 3.16.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ conda install cmake
Retrieving notices: done
Channels:
- defaults
- pytorch
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /home/yongqiang/miniconda3
added / updated specs:
- cmake
The following packages will be downloaded:
package | build
---------------------------|-----------------
cmake-3.26.4 | h96355d8_0 16.7 MB defaults
conda-24.11.1 | py311h06a4308_0 1.2 MB defaults
libuv-1.48.0 | h5eee18b_0 950 KB defaults
rhash-1.4.3 | hdbd6064_0 220 KB defaults
------------------------------------------------------------
Total: 19.1 MB
The following NEW packages will be INSTALLED:
cmake anaconda/pkgs/main/linux-64::cmake-3.26.4-h96355d8_0
libuv anaconda/pkgs/main/linux-64::libuv-1.48.0-h5eee18b_0
rhash anaconda/pkgs/main/linux-64::rhash-1.4.3-hdbd6064_0
The following packages will be UPDATED:
conda 24.11.0-py311h06a4308_0 --> 24.11.1-py311h06a4308_0
Proceed ([y]/n)? y
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ cmake --version
cmake version 3.26.4
CMake suite maintained and supported by Kitware (kitware.com/cmake).
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ ls
CMakeLists.txt cmake-build-debug main.cpp
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ mkdir build
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ cd build
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (7.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/yongqiang/CLionProjects/yongqiang/build
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ make
[ 50%] Building CXX object CMakeFiles/yongqiang.dir/main.cpp.o
[100%] Linking CXX executable yongqiang
[100%] Built target yongqiang
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ ls
CMakeCache.txt CMakeFiles Makefile cmake_install.cmake yongqiang
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ ./yongqiang
Hello, World!
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$
3. Installing CMake
New versions work better for everyone.
References
[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/