gcc 版本切换

Ubuntu14自带GCC的版本是4.8,编译caffe的matlab接口时需要降级到4.7系统使用的gcc版本随着发布版本的不同而不同,在编译Android系统时不同的版本推荐用不同的gcc去编译,那么可不可以改变系统的gcc来适应android编译环境的需求呢?答案是可以的。

先看看我们系统用的gcc和g++是什么版本

gcc -v

可以获得的信息如下

gcc version 4.8

如果我们想使用gcc4.7怎么办?首先看看有没有安装gcc4.7,

ls /usr/bin/gcc*

结果只有/usr/bin/gcc /usr/bin/gcc-4.8两个,那么我们需要安装

sudo apt-get install gcc-4.7 gcc-4.7-multilib g++-4.7 g++-4.7-multilib

安装好后输入以下指令:

sudo update-alternatives –install /usr/bin/gcc gcc /usr/bin/gcc-4.7 50

sudo update-alternatives –install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40

接着输入:

sudo update-alternatives –config gcc

会看到如下的选项

有 3 个候选项可用于替换 gcc (提供 /usr/bin/gcc)。

选择 路径 优先级 状态

  • 0 /usr/bin/gcc-4.7 50 自动模式
    1 /usr/bin/gcc-4.7 50 手动模式
    2 /usr/bin/gcc-4.8 40 手动模式

要维持当前值[*]请按回车键,或者键入选择的编号:

要想用哪个gcc就输入编号吧。

同样也要设置一下g++的

sudo update-alternatives –install /usr/bin/g++ g++ /usr/bin/g++-4.7 50

sudo update-alternatives –install /usr/bin/g++ g++ /usr/bin/g++-4.8 40

如果想删除可选项的话可以键入以下指令:

sudo update-alternatives –remove gcc /usr/bin/gcc-4.7

再用gcc -v 来看一下版本是否改变了。

参考:http://www.linuxidc.com/Linux/2012-10/72284.htm

转自:
http://blog.youkuaiyun.com/d5224/article/details/52261529
https://www.cnblogs.com/zengkefu/p/7103359.html

### 在 VSCode 中配置或切换不同的 GCC 版本 在 VSCode 中切换使用的 GCC 版本,需要对任务配置文件(`tasks.json`)和调试配置文件(`launch.json`)进行修改,以指定不同版本GCC 编译器路径。以下是详细说明: #### 1. 安装多个版本GCC 首先确保系统中已安装多个版本GCC。例如,可以通过 MinGW 或者其他工具链安装不同版本GCC。每个版本GCC 应该具有独立的安装路径[^1]。 #### 2. 修改 `tasks.json` VSCode 使用 `tasks.json` 文件来定义编译任务。可以通过以下方式指定不同版本GCC: - 打开命令面板(`Ctrl+Shift+P`),输入并选择 **Tasks: Configure Task**。 - 创建一个新的任务配置文件或者编辑现有的 `tasks.json` 文件。 - 修改 `command` 字段,指定 GCC 的完整路径。例如: ```json { "version": "2.0.0", "tasks": [ { "label": "build with gcc-8", "type": "shell", "command": "C:/MinGW8/bin/gcc.exe", // 指定 GCC 8 的路径 "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}.exe" ], "group": { "kind": "build", "isDefault": true }, "problemMatcher": ["$gcc"] }, { "label": "build with gcc-11", "type": "shell", "command": "C:/MinGW11/bin/gcc.exe", // 指定 GCC 11 的路径 "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}_gcc11.exe" ], "group": { "kind": "build", "isDefault": false }, "problemMatcher": ["$gcc"] } ] } ``` 通过上述配置,可以分别使用 `gcc-8` 和 `gcc-11` 进行编译[^2]。 #### 3. 修改 `launch.json` 如果需要在调试时切换 GCC 版本,则需要修改 `launch.json` 文件中的 `preLaunchTask` 字段,使其与 `tasks.json` 中的任务标签匹配。例如: ```json { "version": "0.2.0", "configurations": [ { "name": "Debug with gcc-8", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:/MinGW8/bin/gdb.exe", // 指定 GDB 路径 "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "build with gcc-8" // 对应 tasks.json 中的任务 }, { "name": "Debug with gcc-11", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}_gcc11.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:/MinGW11/bin/gdb.exe", // 指定 GDB 路径 "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "build with gcc-11" // 对应 tasks.json 中的任务 } ] } ``` #### 4. 配置 `c_cpp_properties.json` 为了确保 IntelliSense 正确解析代码,还需要在 `c_cpp_properties.json` 文件中指定编译器路径。例如: ```json { "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**" ], "defines": [], "compilerPath": "C:/MinGW8/bin/gcc.exe", // 指定当前使用的 GCC 路径 "cStandard": "c17", "cppStandard": "c++17", "intelliSenseMode": "gcc-x64" } ], "version": 4 } ``` 可以根据需要切换 `compilerPath` 的值,以适应不同的 GCC 版本[^3]。 #### 注意事项 - 如果 GCC 安装在包含空格的路径中,可能需要对路径进行转义或使用引号包裹[^4]。 - 确保每个版本GCC 和对应的 GDB 路径正确无误。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值