在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版本进行编译了!

目录
相关文章
|
4月前
|
安全 Linux iOS开发
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
280 6
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
|
4月前
|
消息中间件 Kafka Linux
Linux下安装Kafka 3.9.1
本文介绍Kafka 3.9.1版本的安装与配置,包括通过ZooKeeper或KRaft模式启动Kafka。涵盖环境变量设置、日志路径修改、集群UUID生成、存储格式化及服务启停操作,适用于Linux环境下的部署实践。
496 0
|
6月前
|
网络协议 关系型数据库 Linux
【App Service Linux】在Linux App Service中安装 tcpdump 并抓取网络包
在App Service for Linux环境中,无法像Windows一样直接使用网络排查工具抓包。本文介绍了如何通过TCPDUMP在Linux环境下抓取网络包,包括SSH进入容器、安装tcpdump、执行抓包命令及下载分析文件的完整操作步骤。
297 5
|
6月前
|
弹性计算 安全 Linux
阿里云服务器ECS安装宝塔Linux面板、安装网站(新手图文教程)
本教程详解如何在阿里云服务器上安装宝塔Linux面板,涵盖ECS服务器手动安装步骤,包括系统准备、远程连接、安装命令执行、端口开放及LNMP环境部署,手把手引导用户快速搭建网站环境。
|
Linux 开发工具 C语言
Linux内核版本升级
本文采用的版本是linux-5.9.tar.gz
441 0
x3d
|
Linux Ubuntu
Linux下的版本升级只是浮云
ubuntu从11.04到11.10,直接系统升级,那简直是扯蛋啊 gnome 也是 从2.32到了3 ,ubuntu从此停在了11.04,对我而言。
x3d
810 0