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, https://yongqiang.blog.csdn.net/

相关推荐
dozenyaoyida2 天前
RISC-V嵌入式开发:彻底解决“undefined reference to isatty“错误全攻略
经验分享·c·cmake·嵌入式开发·isatty·没有定义问题
shanql2 天前
CMake笔记:Linux下常规使用
cmake
zh_xuan3 天前
Android JNI 动态注册:获取系统内存页大小
android·cmake·jni·ndk·动态注册·内存页大小
雪靡4 天前
Visual Studio 2026 优雅的给Cmake设置大代理
c++·ide·cmake·visual studio
郝学胜-神的一滴6 天前
CMake 011:跨平台动态库编译
开发语言·c++·嵌入式硬件·qt·程序人生·cmake·liunx
郝学胜-神的一滴13 天前
CMake 010 :一步到位链接静态库
开发语言·c++·qt·程序人生·系统架构·cmake
草莓熊Lotso14 天前
【CMake】 工程实战:可执行文件从编译、链接到安装全流程深度拆解
linux·运维·服务器·网络·c++·cmake
明月_清风18 天前
Makefile 完全指南:从入门到 CMake 工程化实践
后端·cmake
yuanyuan2o219 天前
从最小项目开始的 CMake 教程
c语言·开发语言·arm开发·c++·makefile·make·cmake
瞎折腾啥啊22 天前
VCPKG详细使用教程
linux·c++·cmake·cmakelists