go: cmd/go: With Go 1.4, cannot statically link a program which imports net
In Go 1.3.x, it was possible to statically link a program which imports the net package. This is important when building programs for cut-down environments, for example busybox.
The problem can be reproduced on Ubuntu as reported by Vasiliy Tolstov:
package main
import "net"
func main() {
_, _ = net.ResolveIPAddr("ip", "google.com")
}
It is possible to statically link this program in Go 1.3.x by issuing:
CGO_ENABLED=0 go build -a -x
but with Go 1.4, the same technique creates the following runtime dependencies:
linux-vdso.so.1 (0x00007fff603fe000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f3bd0608000)
libc.so.6 => /lib64/libc.so.6 (0x00007f3bd0260000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3bd0825000)
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 26 (12 by maintainers)
Commits related to this issue
- Fix static builds in go1.4 https://github.com/golang/go/issues/9344 — committed to thockin/kubernetes by thockin 9 years ago
- Build netdog Previously netdog had to be built with Go 1.3 to ensure it was statically linked. With a workaround to Go bug 9344[1], this is now achievable with Go 1.4. [1]: https://github.com/golang... — committed to cloudfoundry-attic/garden-linux by glyn 9 years ago
- Fix golang/go#9344 for heapster and make downloaded binaries executable — committed to luxas/kubernetes-on-arm by luxas 8 years ago
- Use go flags to compile binaries in static mode So no need to have glibc installed for example — committed to eclipse-che/che-lib by benoitf 8 years ago
- Use Glisp instead of Zygomys While it sucks to switch to an unmaintained project, we don't lose anything from this switch, and we gain a killer feature: gomacs can be staticly compiled (and it is wit... — committed to japanoise/gomacs by japanoise 7 years ago
CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags '-s' src/myapp/myapp.go
Go 1.5.1
LGTM
If you want static compilation always then I recommend installing Go from source
env CGO_ENABLED=0 ./all.bash
That will disable cgo permanently.
On Tue, Oct 20, 2015 at 4:55 PM, dukedougal notifications@github.com wrote: