gpt4 book ai didi

go - 要生成纯静态链接的二进制文件,是否仍然需要在 Go 1.5+ 中使用 -tags netgo 进行编译?

转载 作者:IT王子 更新时间:2023-10-29 00:37:46 42 4
gpt4 key购买 nike

我正在尝试创建一个纯静态链接的二进制文件以在最小的 Docker 容器中运行。在 Go 1.5 之前,我是这样构建它们的:

go build -a -tags netgo -installsuffix netgo myfile.go

我了解到在 1.5 版本中,C 已从 Go 编译器中剥离。是否仍然需要使用 -tags-installsuffix 进行构建?

最佳答案

https://golang.org/doc/go1.5#net

The DNS resolver in the net package has almost always used cgo to access the system interface. A change in Go 1.5 means that on most Unix systems DNS resolution will no longer require cgo, which simplifies execution on those platforms. Now, if the system's networking configuration permits, the native Go resolver will suffice. The important effect of this change is that each DNS resolution occupies a goroutine rather than a thread, so a program with multiple outstanding DNS requests will consume fewer operating system resources.

The decision of how to run the resolver applies at run time, not build time. The netgo build tag that has been used to enforce the use of the Go resolver is no longer necessary, although it still works. A new netcgo build tag forces the use of the cgo resolver at build time. To force cgo resolution at run time set GODEBUG=netdns=cgo in the environment. More debug options are documented here.

This change applies to Unix systems only. Windows, Mac OS X, and Plan 9 systems behave as before.

所以没有。

关于go - 要生成纯静态链接的二进制文件,是否仍然需要在 Go 1.5+ 中使用 -tags netgo 进行编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32416079/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com