基于 CygWin 执行 GoLang 编译报 GCC 错误解决

Windows 上 CygWin 和 GoLang 兼容性还是有不少问题的,编译过程中会报各种异常,例如执行 go get github.com/mattn/go-sqlite3 就会出:

C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingwex
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingw32
collect2: error: ld returned 1 exit status

参考官方文档 https://github.com/golang/go/wiki/cgo

In order to use cgo on Windows, you'll also need to first install a gcc compiler (for instance, mingw-w64) and have gcc.exe (etc.) in your PATH environment variable before compiling with cgo will work.

官方说法是推荐安装的 gcc 编译器是 mingw-w64,所以这种情况只能卸载 CygWin 重装了,推荐安装 TDM-GCC 集成包,下载地址在:

http://tdm-gcc.tdragon.net/download

简单来讲 TDM-GCC 是一个 Windows 上的编译器套件,集成了 GCC 工具集,提供了 MinGW 和 MinGW-w64 的运行时 API,可以执行编译从 Windows98 开始的 32 位或者 64 位二进制文件。

下载完成后全默认下一步,安装完成重新执行编译就会发现完全正常了。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注