在Linux上安装其他版本的cmake 或 升级cmake

简介: 在Linux上安装其他版本的cmake 或 升级cmake

1 问题出现原因

场景:

需要把tensorflow的pb模型,先转为onnx模型,再转换成tensorrt的trt模型,使用的是:

在安装onnx2tensorrt的过程中,需要使用cmake,由于我的版本比较低,因此需要升级cmake的版本

编译:

cmake .. -DTENSORRT_ROOT=../tensorrt_root && make -j

(yolov4) shl@zhihui-mint:~/shl_res/1_project/yolov4-deepsort/checkpoints/onnx-tensorrt/build$ cmake .. -DTENSORRT_ROOT=../tensorrt_root && make -j
CMake Error at CMakeLists.txt:21 (cmake_minimum_required):
  CMake 3.13 or higher is required.  You are running version 3.10.2


-- Configuring incomplete, errors occurred!
(yolov4) shl@zhihui-mint:~/shl_res/1_project/yolov4-deepsort/checkpoints/onnx-tensorrt/build$

2 升级cmake的版本

1、各种cmake版本安装包下载

Cmake Files Downloadhttps://cmake.org/files/

image.png

2、安装教程参考

我使用sudo apt-get install cmake默认安装的是3.10.2,我们这里编译要求cmake的版本至少是3.13以上

卸载旧版本的cmake

apt-get autoremove cmake

最好不要用上面的命令,直接把旧版本cmake所在的目录删除或移动到桌面备份也可以

上面的傻逼命令,会把之前安装的ros很多库包都删除了,以后如果要卸载什么包,最好用命令:sudo apt remove package_nameatutoremove命令不要轻易用

sudo rm -rf /usr/bin/cmake

注意:

旧版本的cmake可以不用卸载的,所以上面的命令也可以不用使用,因为我在卸载旧版本的cmake的时候,它自动把好多依赖都卸载了,把我的ROS系统也卸载了,哎,只想说FK!

3、下载cmake的安装包,这里我下载的是3.16.8

wget https://cmake.org/files/v3.16/cmake-3.16.8-Linux-x86_64.tar.gz

注意:

cmake-3.16.8-Linux-x86_64.tar.gz压缩包里的文件是已经编译过的,解压就可以用!

4、解压

tar zxvf cmake-3.16.8-Linux-x86_64.tar.gz

5、建立软链接

sudo ln -s /home/shl/tools/cmake-3.16.8-Linux-x86_64/bin/cmake /usr/bin/cmake

软链接建立成功,就可以使用cmake了

(base) shl@zhihui-mint:~/tools$ sudo ln -s /home/shl/tools/cmake-3.16.8-Linux-x86_64/bin/cmake /usr/bin/cmake
(base) shl@zhihui-mint:~/tools$ cmake --version
cmake version 3.16.8

CMake suite maintained and supported by Kitware (kitware.com/cmake).
(base) shl@zhihui-mint:~/tools$

3 最简单的升级cmake命令的方法,直接使用pip

3.1 使用pip安装cmake的过程

1、可以用如下的方式,随便指定一个cmake的版本,查看cmake有哪些版本:

pip install cmake==23232

(base) shl@zhihui-mint:/opt/flameshot/build$ pip install cmake==323
Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com
ERROR: Could not find a version that satisfies the requirement cmake==323 (from versions: 0.1.0, 0.2.0, 0.4.0, 0.5.0, 0.6.0, 0.7.0, 0.7.1, 0.8.0, 0.9.0, 3.6.3, 3.6.3.post1, 3.7.2, 3.8.2, 3.9.6, 3.10.3, 3.11.0, 3.11.4, 3.11.4.post1, 3.12.0, 3.13.0, 3.13.1, 3.13.2, 3.13.2.post1, 3.14.3, 3.14.3.post1, 3.14.4, 3.14.4.post1, 3.15.3, 3.15.3.post1, 3.16.3, 3.16.3.post1, 3.16.5, 3.16.6, 3.16.7, 3.16.8, 3.17.0, 3.17.1, 3.17.2, 3.17.3, 3.18.0, 3.18.2, 3.18.2.post1, 3.18.4, 3.18.4.post1, 3.20.2, 3.20.3)
ERROR: No matching distribution found for cmake==323
(base) shl@zhihui-mint:/opt/flameshot/build$

2、安装我们自己需要的cmake版本

pip install -U cmake==3.17.3

(base) shl@zhihui-mint:/opt/flameshot/build$ pip install -U cmake==3.17.3
Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com
Collecting cmake==3.17.3
  Downloading cmake-3.17.3-py3-none-manylinux1_x86_64.whl (17.6 MB)
     |████████████████████████████████| 17.6 MB 331 kB/s 
Installing collected packages: cmake
Successfully installed cmake-3.17.3
(base) shl@zhihui-mint:/opt/flameshot/build$

3、查看安装好的cmake版本

cmake --version

如下,已经成功安装了指定的cmake的版本3.17.3

(base) shl@zhihui-mint:/opt/flameshot/build$ cmake --version
cmake version 3.17.3

3.2 编译的时候没有使用pip安装的cmake进行编译

当用cmake编译的时候用的还是系统中旧的cmake版本,我们需要把这个cmake指定为我们新安装的版本

(base) shl@zhihui-mint:/opt/flameshot/build$ sudo cmake ..
[sudo] password for shl:       
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
  CMake 3.13 or higher is required.  You are running version 3.10.2


-- Configuring incomplete, errors occurred!
(base) shl@zhihui-mint:/opt/flameshot/build$ cmake --version
cmake version 3.17.3

CMake suite maintained and supported by Kitware (kitware.com/cmake).
(base) shl@zhihui-mint:/opt/flameshot/build$

1、删除之前旧的cmake版本

sudo rm -rf /usr/bin/cmake

(base) shl@zhihui-mint:/opt/flameshot/build$ ll /usr/bin/cmake 
-rwxr-xr-x 1 root root 5325648 44 22:10 /usr/bin/cmake*
(base) shl@zhihui-mint:/opt/flameshot/build$ sudo rm -rf /usr/bin/cmake

2、查看我们新安装cmake可执行文件路径

which cmake

(base) shl@zhihui-mint:/opt/flameshot/build$ which cmake
/home/shl/anaconda3/bin/cmake
(base) shl@zhihui-mint:/opt/flameshot/build$

3、把新安装的cmake建立系统cmake路径的软链接

sudo ln -s /home/shl/anaconda3/bin/cmake /usr/bin/cmake

(base) shl@zhihui-mint:/opt/flameshot/build$ sudo ln -s /home/shl/anaconda3/bin/cmake /usr/bin/cmake

之后就可以正确使用新的cmake版本进行编译了!

目录
相关文章
|
16天前
|
Ubuntu Linux
查看Linux系统架构的命令,查看linux系统是哪种架构:AMD、ARM、x86、x86_64、pcc 或 查看Ubuntu的版本号
查看Linux系统架构的命令,查看linux系统是哪种架构:AMD、ARM、x86、x86_64、pcc 或 查看Ubuntu的版本号
130 3
|
11天前
|
NoSQL 关系型数据库 Redis
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
mall在linux环境下的部署(基于Docker容器),docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongodb、minio详细教程,拉取镜像、运行容器
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
|
10天前
|
Ubuntu Linux Shell
Linux系统命令 安装和文件相关命令
本文档详细介绍了Linux系统中的常用命令,包括软件安装卸载命令如`dpkg`和`apt-get`,压缩与解压命令如`gzip`、`bzip2`和`xz`,以及`tar`命令用于打包和解包。此外还介绍了文件分割命令`split`,文件操作命令如`cat`、`head`、`tail`、`more`、`less`等,管道命令和`wc`、`grep`、`find`、`cut`、`sort`、`uniq`、`diff`等实用工具。最后,文档还讲解了文件属性相关的命令如`chmod`、`chown`、`chgrp`以及创建硬链接和软链接的`ln`命令。
|
12天前
|
安全 Linux API
关于Linux稳定版本的一切你想知道的内容 【ChatGPT】
关于Linux稳定版本的一切你想知道的内容 【ChatGPT】
|
13天前
|
Linux 编译器 C语言
Linux内核对GCC版本的检测
Linux内核对GCC版本的检测
|
16天前
|
人工智能 Linux 开发工具
Linux安装Taiyi stable-diffusion-webui
Linux安装Taiyi stable-diffusion-webui
|
Linux 开发工具 C语言
Linux内核版本升级
本文采用的版本是linux-5.9.tar.gz
229 0
x3d
|
Linux Ubuntu
Linux下的版本升级只是浮云
ubuntu从11.04到11.10,直接系统升级,那简直是扯蛋啊 gnome 也是 从2.32到了3 ,ubuntu从此停在了11.04,对我而言。
x3d
748 0