英文:
Running gcc failed while building go project in windows
问题
我尝试使用go build
编译我的项目,但是出现了以下错误:
> C:\Go\pkg\tool\windows_amd64\link.exe: 运行 gcc 失败: 退出状态 1
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld: 找不到 -lmingwex
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld: 找不到 -lmingw32
collect2: 错误: ld 返回了退出状态 1
我了解到在 Windows 上使用 gcc 链接文件是编译 Go 项目的一个问题。但是我已经在我的 Windows 系统上安装了 gcc,但错误仍然存在。我可以看到上面的错误引用了一个 Linux 系统中的 gcc (/usr/lib),那么编译器如何检测到我的 gcc 安装呢?
编辑:
我的 go env
set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\Go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\wildan\AppData\Loc
al\Temp\go-build554990027=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1
set PKG_CONFIG=pkg-config
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
使用的 go 版本为 1.8
英文:
I tried compiling my project using go build
and I get this error:
> C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingwex
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingw32
collect2: error: ld returned 1 exit status
I've read that linking files with gcc is a problem in compiling go projects with Windows. But I have installed gcc in my Windows system but the error persists. I can see the error above references gcc as in a Linux sistem (/usr/lib) so how would the compiler detect my gcc installation?
EDIT:
My go env
set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\Go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\wildan\AppData\Loc
al\Temp\go-build554990027=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1
set PKG_CONFIG=pkg-config
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
Using go version 1.8
1: https://github.com/golang/go/issues/9510 "problem"
答案1
得分: 7
你正在使用Cygwin来寻找MinGW库。不要使用Cygwin,而是使用MinGW的GCC编译器。我推荐使用TDM-GCC。
英文:
> /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld:
> cannot find -lmingw32 collect2
You are using cygwin to look for mingw libraries. Don't use cygwin; use a mingw gcc compiler. I use TDM-GCC.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论