常见问题之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 国际许可协议 进行许可。

目录
相关文章
|
7月前
|
算法 编译器 C语言
【2026最新】MinGW64官网下载安装保姆级教程(附安装包+图文并茂)
MinGW-w64 是 Windows 下的轻量级 GNU 编译器集合,支持 C/C++ 编译,无需虚拟机即可生成独立 exe 文件。它体积小、免安装、静态链接运行库,兼容 Win10/11 与旧系统,配置简单,广泛用于算法开发、刷题及教学场景。
12911 4
|
11月前
|
人工智能 JavaScript 开发工具
极速上手!Claude Code 原生支持 Windows 免WSL安装教程
Claude Code 现已支持 Windows 原生运行,无需 WSL 配置。本文提供详细安装教程,涵盖 Node.js 环境验证、Git 安装及 Claude Code 配置步骤,助你快速上手这一强大 AI 编程工具。
13186 13
|
9月前
|
机器学习/深度学习 人工智能 前端开发
终端里的 AI 编程助手:OpenCode 使用指南
OpenCode 是开源的终端 AI 编码助手,支持 Claude、GPT-4 等模型,可在命令行完成代码编写、Bug 修复、项目重构。提供原生终端界面和上下文感知能力,适合全栈开发者和终端用户使用。
58970 11
|
前端开发 JavaScript Linux
用 Go 写桌面应用?试试 Wails 吧!
Wails 是一个结合 Go 语言与前端技术(如 Vue、React)开发轻量级桌面应用的框架。相比 Electron,它更轻、更快,资源占用更低,支持跨平台打包,适合熟悉 Web 开发又追求原生性能的开发者。
2489 0
|
Ubuntu 安全 定位技术
ubuntu桌面版安装教程
完成 Ubuntu 22.04.1 LTS 安装 重启后,看到如下界面,请按【回车】键 使用之前设置的用户名和密码登录系统

热门文章

最新文章