当前位置:

常见问题之Golang——cgo: C compiler “gcc” not found: exec: “gcc”: executable file not found in %PATH%错误

本文最后更新于2022-07-27,已超过 1年没有更新,如果文章内容、图片或者下载资源失效,请留言反馈,我会及时处理,谢谢!

温馨提示:本文共3016个字,读完预计8分钟。

文章目录

常见问题之Golang——cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in %PATH%错误

背景

本系列文章均为学习过程中记录的笔记,欢迎和我一起来学习Go语言。

全文使用环境如下:

  • 操作系统:windows10
  • 使用工具:Goland开发工具
  • golang版本:1.17

简介

本文主要是对我日常在使用golang时遇到的一些问题与解决方式进行的汇总,在此提供给大家便于排查一些遇到的问题,其中有更好的解决方案可在评论区留言。

正文

错误

cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in %PATH%

Compilation finished with exit code 2

造成原因分析:

缺少gcc编译器,需要进行安装

解决方案:

下载x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z

1、进行下载基础程序并进行安装
常见问题之Golang——cgo: C compiler “gcc” not found: exec: “gcc”: executable file not found in %PATH%错误-Mr.Li's Blog

这里我们直接使用在线安装即可,通常你能打开这个下载页,基本上在线安装也没有啥问题,怕出问题你就打开访问国外网站就行。

常见问题之Golang——cgo: C compiler “gcc” not found: exec: “gcc”: executable file not found in %PATH%错误-Mr.Li's Blog

注意:这里需要根据系统是64还是32位进行选择,一般我们的系统都是64位的,改为x86_64即可。

常见问题之Golang——cgo: C compiler “gcc” not found: exec: “gcc”: executable file not found in %PATH%错误-Mr.Li's Blog

选择好一个要安装的位置,就等着它装完吧

常见问题之Golang——cgo: C compiler “gcc” not found: exec: “gcc”: executable file not found in %PATH%错误-Mr.Li's Blog
2、安装完成后,将该程序的命令程序可以在cmd中调用起来

打开系统环境变量,在系统path变量上面追加一下刚才安装的bin文件夹,如下图所示:

常见问题之Golang——cgo: C compiler “gcc” not found: exec: “gcc”: executable file not found in %PATH%错误-Mr.Li's Blog
3、打开cmd,进行输入gcc -v 查看是否能有效加载起来刚才配置
C:\Users\cnhuashao>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=D:/Program\ Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/8.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-8.1.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-posix-seh-rev0, Built by MinGW-W64 project' --with-bugurl=https://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=' -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/lib -L/c/mingw810/prerequisites/x86_64-zlib-static/lib -L/c/mingw810/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)

4、重启一下之前报错的程序或Goland,再次进行启动程序尝试,恢复正常。

本文声明:

知识共享许可协议

本作品由 cn華少 采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可。

本文链接:,转发请注明来源!
评论已关闭。