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

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

常见问题之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编译器,需要进行安装

解决方案:

1、进行下载基础程序并进行安装

image.png

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

image.png

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

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

image.png

2、安装完成后,将该程序的命令程序可以在cmd中调用起来

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

image.png

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,再次进行启动程序尝试,恢复正常。

本文声明:

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

目录
相关文章
conda常用操作和配置镜像源
conda常用操作和配置镜像源
29165 0
|
算法 数据安全/隐私保护 Windows
|
6月前
|
存储 供应链 监控
1688商品数据实战:API搜索接口开发与供应链分析应用
本文详细介绍了如何通过1688开放API实现商品数据的获取与应用,涵盖接入准备、签名流程、数据解析存储及商业化场景。开发者可完成智能选品、价格监控和供应商评级等功能,同时提供代码示例与问题解决方案,确保法律合规与数据安全。适合企业开发者快速构建供应链管理系统。
|
安全 Go 开发工具
go clean命令 完全解析
go clean命令 完全解析
1270 0
|
存储 设计模式 Java
阿里官方代码规范
这篇文章详细介绍了阿里巴巴官方的代码规范,包括命名规则、常量使用、方法覆写、并发处理、注释规范、数据库设计等多个方面,旨在提高代码的可读性、维护性和扩展性。
|
JSON Prometheus Cloud Native
Grafana 系列文章(十二):如何使用 Loki 创建一个用于搜索日志的 Grafana 仪表板
Grafana 系列文章(十二):如何使用 Loki 创建一个用于搜索日志的 Grafana 仪表板
|
Ubuntu 应用服务中间件 Linux
nginx 配置代理ip访问https的域名配置
nginx 配置代理ip访问https的域名配置
2568 2
|
Linux Go Windows
go windows编译linux可执行文件
go windows编译linux可执行文件
8991 0
|
数据可视化 BI C#
C#程序采用AOT发布,真的可以避免被反编译?
C#程序采用AOT发布,真的可以避免被反编译?
1586 0
|
存储 缓存 芯片