Installing CMake (安装 CMake)

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,

相关推荐
PyGata6 天前
CMake学习笔记(一)
学习笔记·cmake·cmakelists
charlee447 天前
CMake构建学习笔记26-OpenBLAS库的构建
多线程·cmake·openblas·blas/lapack
charlee448 天前
CMake构建学习笔记30-Ceres Solver库的构建
静态库·非线性优化·cmake·buildcppdependency·ceres solver
charlee449 天前
CMake构建学习笔记28-gmp&mpfr库的构建
cmake
charlee449 天前
CMake构建学习笔记27-初步完成C&C++自动化构建工具
跨平台·cmake·构建·依赖管理
羑悻的小杀马特12 天前
现代 CMake 项目构建完全指南:从基础配置到高级技巧的目标属性管理与智能依赖传递机制解析
cmake·项目构建·属性传递机制
Theliars18 天前
Ubuntu 上使用 VSCode 调试 C++ (CMake 项目) 指南
c++·vscode·ubuntu·cmake
Molesidy1 个月前
【Embedded System】【CMake】Windows下CMake+VSCode的开发环境搭建以及初步认识
ide·vscode·编辑器·cmake
fedorayang1 个月前
precompilation-headers 以及在cmake中的实现
cmake