VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

时间:2022-03-14 12:54:24

1、问题描述

由于安装VS15 Preview 5,搞的系统由重新安装一次;在用vscdoe编译go语言时,出现以下问题:

# odbc
exec: "gcc": executable file not found in %PATH%
exit status 2

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

2、解决方案

2.1 mingw 64

MinGW分为较早开发的MinGW32和之后为编译64位程序开发的MinGW-w64,MinGW32只能编译32位的程序,而mingw64不仅能编译64位程序,也能编译32位程序,还能进行交叉编译,即在32位主机上编译64位程序,在64位主机上编译32位程序。

由于用的window10 企业版64位操作系统,要下载mingw 64位(官网地址:http://mingw-w64.org/doku.php),下载地址:https://sourceforge.net/projects/mingw-w64/

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

点击“Download”按钮,

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

2.2 安装须知

在使用mingw64之前,由于其支持较多的编译类型,所以其安装包较多,需要了解其安装包的命名规则:http://sourceforge.net/apps/trac/mingw-w64/wiki/download%20filename%20structure

一般采用personal文件夹下的两个版本的包编译64位程序:https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

threads-win32是编译目标程序是32位,threads-posix是编译目标程序是64位

2.3 安装过程

下载mingw-w64-install.exe之后进行安装(离线安装,比较慢,可以):

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

根据系统环境,选择相关配置:

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

选择安装路径:

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

下载比较慢,耐心等待……

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

这个安装过程是在折磨人,可以下载对应的压缩包。

2.3 环境测试

在cmd下,打开C:\mingw-w64\i686-6.2.0-posix-dwarf-rt_v5-rev1\mingw32\bin目录,输入gcc -v,出现如下图,说明安装成功:

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

2.4 卸载

转到C:\mingw-w64\i686-6.2.0-posix-dwarf-rt_v5-rev1目录,双击uninstall.exe打开卸载程序,如下图:

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

2.5 通过压缩包安装

下载压缩包,解压到C:\mingw64目录下,如下图:

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

在cmd窗口下,转到C:\mingw64\bin,输入gcc -v,显示如下:

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

OK,到此,两种方法都成功。

3、应用测试

安装成功后,如何让go编译器调用gcc呢?需要设置环境变量path,如下添加C:\mingw64\bin到path环境变量值下:

VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

再次编译go语言,问题已解决~~~~