win32: 使用go编译go自身 - Go语言中文社区

win32: 使用go编译go自身


因项目需要,需要重新编译go。

本文记录使用go编译go自身的流程,方便后面继续修改编译:

如直接自己编译自己,会出现下面的错误:

$ cd /c/go/src  
$ ./make.bat  
Building Go cmd/dist using C:Go  
go tool: no such tool "compile"  
go tool: no such tool "compile"  
go tool: no such tool "compile"  
go tool: no such tool "compile"  
go tool: no such tool "compile"  
go tool: no such tool "compile"  
go tool: no such tool "compile"  
go tool: no such tool "compile" 

查看go env发现也没任何错误:


$ go env  
set GOARCH=amd64  
set GOBIN=  
set GOCACHE=C:UsersMikeAppDataLocalgo-build  
set GOEXE=.exe  
set GOHOSTARCH=amd64  
set GOHOSTOS=windows  
set GOOS=windows  
set GOPATH=E:devgolang  
set GORACE=  
set GOROOT=c:go  
set GOTMPDIR=  
set GOTOOLDIR=c:gopkgtoolwindows_amd64  
set GCCGO=gccgo  
set CC=gcc  
set CXX=g++  
set CGO_ENABLED=1  
set CGO_CFLAGS=-g -O2  
set CGO_CPPFLAGS=  
set CGO_CXXFLAGS=-g -O2  
set CGO_FFLAGS=-g -O2  
set CGO_LDFLAGS=-g -O2  
set PKG_CONFIG=pkg-config  
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:UsersMikeAppDataLocalTempgo-build976029818=/tmp/go-build -gno-record-gcc-switches  

怀疑是其他地方的问题。折腾了半天,后来发现

GOTOOLDIR 为空

使用bootstrap源码编译工具链

参考这里的说明,先下载 go1.4-bootstrap-20171003.tar.gz,使用已经下载的go编译,日志如下:


$ GOOS=windows GOARCH=amd64 ./make.bat  
# Building C bootstrap tool.  
cmd/dist  
  
# Building compilers and Go bootstrap tool.  
E:gosrclib9fmtfltfmt.c: In function '__efgfmt':  
E:gosrclib9fmtfltfmt.c:437:5: warning: this statement may fall through [-Wi                        mplicit-fallthrough=]  
   if(ndigits > prec) {  
     ^  
E:gosrclib9fmtfltfmt.c:451:2: note: here                 

省略大部分日志 

---  
Installed Go for windows/amd64 in E:go  
Installed commands in E:gobin

可以看到,编译时间已经更新:


123

修改GOROOT_BOOTSTRAP,设置为E:go,重新编译

$ GOOS=windows GOARCH=amd64 ./make.bat
# Building C bootstrap tool.

可以看到,编译时间已经更新:




版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/zanget/article/details/80604018
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2019-08-27 20:06:12
  • 阅读 ( 2350 )
  • 分类:Go

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢