以前在Ubuntu22上编译的时候用的gcc11,现在升级到ubuntu24,发现编译不行了,版本升级到了gcc13。只好开始找解决方案。
1、安装多个版本
sudo apt update $ sudo apt install build-essential $ sudo apt -y install gcc-11 g++-11 gcc-13 g++-13 2、使用 update-alternatives 工具创建多个 GCC 和 G++ 编译器替代方案的列表:
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11 $ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 11 $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 13 $ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 13
3、检查 Ubuntu 系统上可用的 C 和 C++ 编译器列表,并通过输入相关的选择编号来选择所需的版本:
$ sudo update-alternatives --config gcc There are 3 choices for the alternative gcc (providing /usr/bin/gcc). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/bin/gcc-9 9 auto mode 1 /usr/bin/gcc-10 10 manual mode * 2 /usr/bin/gcc-8 8 manual mode 3 /usr/bin/gcc-9 9 manual mode Press to keep the current choice[*], or type selection number:
对于 C++ 编译器执行:
$ sudo update-alternatives --config g++ There are 3 choices for the alternative g++ (providing /usr/bin/g++). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/g++-9 9 auto mode 1 /usr/bin/g++-10 10 manual mode 2 /usr/bin/g++-8 8 manual mode 3 /usr/bin/g++-9 9 manual mode Press to keep the current choice[*], or type selection number:
4、每次切换后检查您当前选择的编译器版本:
$ gcc --version $ g++ --version
这样就简单多了。
因篇幅问题不能全部显示,请点此查看更多更全内容
怀疑对方AI换脸可以让对方摁鼻子 真人摁下去鼻子会变形
女子野生动物园下车狼悄悄靠近 后车司机按喇叭提醒
睡前玩8分钟手机身体兴奋1小时 还可能让你“变丑”
惊蛰为啥吃梨?倒春寒来不来就看惊蛰
男子高速犯困开智能驾驶出事故 60万刚买的奔驰严重损毁