Ubuntu更改CMAKE和C++版本

在代码移植的过程中,因为ubuntu版本的不同,经常会出现代码在新环境中编译不通过,其中有很多因素是因为camke和C++的版本不同,下面将给出方案。

  • 更改Cmake版本
sudo apt remove cmake #删除旧版本的cmake

sudo apt-get install build-essential libssl-dev

wget https://github.com/Kitware/CMake/releases/download/v3.20.0/cmake-3.20.0.tar.gz


tar -zxvf cmake-3.20.0.tar.gz
cd cmake-3.20.0
./bootstrap
make
sudo make install

cmake --version 

cp /home/user/cmake-3.20.0/bin/cmake /usr/bin/

注意在更换CMAKE时,ROS需要重新安装一遍

  • 更换C++版本

添加编译链

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update

安装

sudo apt-get install gcc-9 g++-9

修改C++的优先顺序,最后的值越大越优先

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 100
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50

#删除优先顺序
sudo update-alternatives gcc /usr/bin/g++-5

切换版本

sudo update-alternatives --config g++

猜你喜欢

转载自blog.csdn.net/HUASHUDEYANJING/article/details/131335141