网络原因引起的 Golang 编译错误

由于众所周知的原因,强大的 GFW 会引起 Go 语言编译时在对DNS相关进行测试时失败。当然如果人品不错,没有公网连接,不受GFW的影响……还是会在网络相关的那部分包的测试中失败。导致无法正常安装 Golang。

错误信息类似如下形式:

...
test math
test mime
test mime/multipart
test net
TEST FAIL net
make[1]: Entering directory `/home/mikespook/bin/go/src/pkg/net'
gotest -test.short -test.timeout=120
rm -f _test/net.a
8g -o _gotest_.8 cgo_stub.go dial.go dnsmsg.go fd_linux.go hosts.go ip.go ipsock.go iprawsock.go lookup.go net.go parse.go pipe.go sock.go tcpsock.go udpsock.go unixsock.go  newpollserver.go fd.go file.go dnsconfig.go dnsclient.go port.go  dialgoogle_test.go dnsname_test.go file_test.go hosts_test.go ip_test.go ipraw_test.go multicast_test.go net_test.go parse_test.go pipe_test.go port_test.go server_test.go srv_test.go timeout_test.go
rm -f _test/net.a
gopack grc _test/net.a _gotest_.8 
--- FAIL: net.TestLookupCNAME (0.02 seconds)
	LookupCNAME("www.google.com.") = "www-g-com-chn.l.google.com.", <nil>, want "www.l.google.com.", nil
FAIL
gotest: "./8.out -test.short=true -test.timeout=120" failed: exit status 1
make[1]: *** [testshort] Error 2
make[1]: Leaving directory `/home/mikespook/bin/go/src/pkg/net'
make: *** [net.testshort] 错误 1

解决这个问题的办法很简单,之前在推上我也有发过。但是自己安装 Golang 的时候遇到网络异常,却经常忘记这个设置,接二连三的要动手查 Makefile 。随记录于此,方便备查。

按照 Golang weekly.2011-04-13 版本来说,$GOROOT/src/pkg/Makefile 文件、205-208 行是用于屏蔽无外网情况下测试的:

# Disable tests that depend on an external network.
ifeq ($(DISABLE_NET_TESTS),1)
NOTEST+=net syslog
endif

我们看到一个环境变量 $DISABLE_NET_TESTS,当其等于 1 时就可以屏蔽外部网络测试。

因此,在 shell 中设定这个环境变量:

export DISABLE_NET_TESTS=1

即可正常编译 Golang 了。

Join the Conversation

2 Comments

Leave a comment

Your email address will not be published. Required fields are marked *