ubuntu 里切换 gcc,g++ 的版本
https://askubuntu.com/questions/26498/choose-gcc-and-g-version
https://stackoverflow.com/questions/7832892/how-to-change-the-default-gcc-compiler-in-ubuntu
https://codeyarns.com/2015/02/26/how-to-switch-gcc-version-using-update-alternatives/
关于 update-alternatives 命令的帮助: http://www.cnblogs.com/welhzh/p/7339632.html
First erased the current update-alternatives setup for gcc and g++:
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
Install Packages
It seems that both gcc-4.3 and gcc-4.4 are installed after install build-essential. However, we can explicitly install the following packages:
sudo apt-get install gcc-4.3 gcc-4.4 g++-4.3 g++-4.4
Install Alternatives
Symbolic links cc and c++ are installed by default. We will install symbol links for gcc and g++, then link cc and c++ to gcc and g++ respectively.
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.3 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 20
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
Configure Alternatives
The last step is configuring the default commands for gcc, g++. It's easy to switch between 4.3 and 4.4 interactively:
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
Or switch using script:
#!/bin/sh
if [ -z "$1" ]; then
echo "usage: $0 version" 1>&2
exit 1
fi
if [ ! -f "/usr/bin/gcc-$1" ] || [ ! -f "/usr/bin/g++-$1" ]; then
echo "no such version gcc/g++ installed" 1>&2
exit 1
fi
update-alternatives --set gcc "/usr/bin/gcc-$1"
update-alternatives --set g++ "/usr/bin/g++-$1"
Here's a complete example of jHackTheRipper's answer for the TL;DR crowd. :-) In this case, I wanted to run g++-4.5 on an Ubuntu system that defaults to 4.6. As root
:
apt-get install g++-4.5
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 100
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.5 50
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 100
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.5 50
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.6 100
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.5 50
update-alternatives --set g++ /usr/bin/g++-4.5
update-alternatives --set gcc /usr/bin/gcc-4.5
update-alternatives --set cpp-bin /usr/bin/cpp-4.5
Here, 4.6 is still the default (aka "auto mode"), but I explicitly switch to 4.5 temporarily (manual mode). To go back to 4.6:
update-alternatives --auto g++
update-alternatives --auto gcc
update-alternatives --auto cpp-bin
(Note the use of cpp-bin
instead of just cpp
. Ubuntu already has a cpp
alternative with a master link of /lib/cpp
. Renaming that link would remove the /lib/cpp
link, which could break scripts.)
ubuntu 里切换 gcc,g++ 的版本的更多相关文章
- gcc/g++多版本切换 (ubuntu18.04)
使用Ubuntu18.04已经有一段时间了,在使用过程中经常需要处理不同软件的编译工作,但是这时候就遇到这样一个问题,那就是不同软件,甚至是同一个软件的不同版本都会使用不同版本的gcc/g++来进行编 ...
- ubuntu 14.04 gcc/g++版本降低
Matlab 2014a支持的gcc/g++版本是4.7x,而ubuntu 14.04以及更高版本默认安装的版本都是4.8及以上,因此需要降低gcc/g++版本,方法如下: 1 安装 $ sudo a ...
- Debian/Ubuntu 已安装gcc/g++ 4.8.1
gcc 4.8.1 是第一个全然支持C++11(C++14非常可能在gcc 4.9.0開始支持.)的编译器,Windows上能够安装mingw版的.在sourceforge 上有下载.安装也比較方便. ...
- 通过yum升级gcc/g++至版本4.8.2
最近在坐一个日期处理的问题,需要安装sxtwl模块,但是gcc版本4.7死活也安装不上,最后测试到只能升级gcc版本到4.8才得以解决 [root@123 bin]# gcc -vUsing buil ...
- ubuntu下切换默认的python版本
Ubuntu系统自带python2.7(默认)和python3.5,所以不需要自己安装python.我们可以使用命令python -V或python3 -V来查看默认的python版本. 现在越来越多 ...
- ubuntu 18.04 gcc g++降级4.8版
$ sudo apt-get install -y gcc-4.8 $ sudo apt-get install -y g++-4.8 $ cd /usr/bin $ sudo rm gcc $ su ...
- ubuntu 14.04 更新 gcc/g++ 4.9.2
ubuntu 14.04 更新 gcc/g++ 4.9.2 最近看到c++11非常的好用,尤其是自带了regex,于是稍微学了一下c++11的新特性.可是我在编译一个regex程序是却发现稍微复杂一点 ...
- ubuntu 16.04 更新 gcc/g++ 4.9.2
ubuntu 转载 2016年10月12日 :: 标签:ubuntu /g++ /gcc [html] view plain copy sudo dpkg -l g++ 最近在学C++primer , ...
- ubuntu下安装低级版本gcc/g++ 并随意切换
来自:http://blog.sina.com.cn/s/blog_6cee149d010129bl.html 发现Android的版本中编译Host的程序经常因为本机的Gcc版本过高,需要这样那样的 ...
随机推荐
- 【转】IAR for STM8介绍、下载、安装与注册
Ⅰ.写在前面 本文讲述的内容是IAR for STM8(EWSTM8)的介绍.下载.安装与注册,其安装.注册过程和IAR for ARM类似,如果需要了解IAR for ARM相关的文章,可以到我博客 ...
- JDK源码分析(6)ConcurrentHashMap
JDK版本 ConcurrentHashMap源码分析 table:默认为null,初始化发生在第一次插入操作,默认大小为16的数组,用来存储Node节点数据,扩容时大小总是2的幂次方. nextTa ...
- 面试 -- fragment生命周期
Android 3.0 (Api 11)引入: Fragment具有重用,易适配(平板和手机之间的)优点: 依赖Activity,生命周期受到Activity的生命周期影响: fragment生命周期 ...
- RMQ求解->ST表
ST表 这是一种神奇的数据结构,用nlogn的空间与nlongn的预处理得出O(1)的区间最大最小值(无修) 那么来看看这个核心数组:ST[][] ST[i][j]表示从i到i+(1<<j ...
- 解码(ByteBuffer): CharsetDecoder.decode() 与 Charset.decode() 的不同
今天测试的时候发现一个问题: ByteBuffer inputBuffer = ByteBuffer.allocate(1024); StringBuilder inputData = new Str ...
- linux下设置默认路径
查看文件: vim ~/.bash_profile 在bash_profile文件下以编辑模式插入以下代码:其中,/xxx/myname即为要设置的默认路径 SYSTEM=`uname -s` cas ...
- UML简单熟悉
+ :代表public - :代表private # :代表protected 实现,继承关系:implements,extends 关联关系:使一个类知道另一个类的属性和方法 每一个Driver类 ...
- Codeforces Round #525 (Div. 2) Solution
A. Ehab and another construction problem Water. #include <bits/stdc++.h> using namespace std; ...
- poj 2976(二分搜索+最大化平均值)
传送门:Problem 2976 参考资料: [1]:http://www.hankcs.com/program/cpp/poj-2976-dropping-tests-problem-solutio ...
- 安装架设Apache+MySQL+PHP网站环境
转载自 http://blog.sina.com.cn/s/blog_c02ed6590101d2sl.html 并进行了个人编辑整理 一.安装 MySQL 首先来进行 MySQL 的安装.打开超级终 ...