Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

And smaller binary size too. For a statically linked blob, that's a big plus.


BTW, what does one have to do to get fully statically linked executables? The binaries I've created with go get SOMETHING are linking against libc, but I remember that go doesn't rely on the system libc. Has that changed? For instance I just installed git-appraise, and it's a dynamically linked executable. What am I doing wrong?


Go generally links to libc to use the system's getaddrinfo-- some OSes override it to do special things with dynamically discovered hosts on local networks, interfacing with LDAP/AD, etc.

If you use `CGO_ENABLED=0 go build`, it should make a statically linked executable.


I don't believe that has been true for a few releases now. I believe go defaults to a pure Go resolver implementation now. You have to force enable the cgo resolver.

https://golang.org/pkg/net/


from the same page:

"When cgo is available, the cgo-based resolver is used instead under a variety of conditions: on systems that do not let programs make direct DNS requests (OS X), when the LOCALDOMAIN environment variable is present (even if empty), when the RES_OPTIONS or HOSTALIASES environment variable is non-empty, when the ASR_CONFIG environment variable is non-empty (OpenBSD only), when /etc/resolv.conf or /etc/nsswitch.conf specify the use of features that the Go resolver does not implement, and when the name being looked up ends in .local or is an mDNS name."


By some OSes, you mean any Linux distro with Avahi installed, right? I'm assuming getaddrinfo checks NSS for where to look up hostnames.

I should also check how Windows with Bonjour behaves.


It is probably the net package. The net package depends on cgo and libc for some DNS resolution. There is a pure Go implementation, but the cgo one is used if cgo is available. If you disable cgo as the other comments say, the pure Go implementation will be used instead. Alternatively, you can not include the net package.

Search for systemConf().canUseCgo()

https://github.com/golang/go/blob/master/src/net/lookup_unix...


CGO_ENABLED=0

Otherwise it will dynamically link glibc in case of CGO code.

Note: the race detector does not work without cgo enabled.


Most likely it depends on the `net` package which can use `getaddrinfo` for dns lookups. Try using the `netgo` build tag:

    go install -tags=netgo github.com/google/git-appraise/git-appraise


I tried that and also

    env CGO_ENABLED=0 go get github.com/google/git-appraise/git-appraise
but I always get an error that go wants to write net.a in /usr/lib, which I naturally am not allowed to do because it's owned by the distro (Arch) go package:

    go install net: open /usr/lib/go/pkg/linux_amd64/net.a: permission denied
I have only set GOPATH to ~/.go and nothing else. Any other GO environment variable I should have used?


Go needs to re-build the stdlib packages with the new build tag as well.

You could install go locally somewhere in ~ and point GOROOT there.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: