背景


安装gorm包时,出现gcc报错:

1
2
3
4
5
6
D:\Project\Go\GinDemo\15gin_file>go get -u gorm.io/driver/sqlite
go: downloading gorm.io/driver/sqlite v1.1.4
go: downloading github.com/mattn/go-sqlite3 v1.14.5
go: downloading github.com/mattn/go-sqlite3 v1.14.6
# github.com/mattn/go-sqlite3
cgo: exec gcc: exec: "gcc": executable file not found in %PATH%

解决


可以在MinGW-w64下载离线安装包。

下载了x86_64-posix-sjlj的压缩包,如图所示,然后解压缩便得到了mingw64。

mingwu1.png

直接将bin路径添加到环境变量中即可。

  • 在系统变量中,新增:GCC_HOME:C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw643LIBRARY_PATH:%GCC_HOME%\lib%GCC_HOME%\lib:%GCC_HOME%\include

  • path中新增:%GCC_HOME%\bin

验证:

1
2
3
4
5
PS C:\Users\zaneliu> gcc -v
Using built-in specs.
COLLECT_GCC=C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\gcc.exe
...
gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)