On Sun, Jan 31, 2021 at 5:54 AM Hongyi Zhao <hongyi.z...@gmail.com> wrote: > > If the go program compiled by a completely static compiled version of go > binary compiler will also be static automatically? To be more specific, on > Ubuntu 20.04, I've compiled the latest git master version of go compiler in a > completely static manner as shown below: > > $ which go | xargs file > /home/werner/Public/repo/github.com/golang/go.git/bin/go: ELF 64-bit LSB > executable, x86-64, version 1 (SYSV), statically linked, Go > BuildID=5jq4NVhOUQBZ9qoSzZZP/ZGpiMeW1vV69o1mL-B9A/6YaUKXNOw58uUviv4EeO/4sUw0l9CinylaK_Pov59, > not stripped > > Then I try to build the dnsproxy by the following steps: > > $ git clone https://github.com/AdguardTeam/dnsproxy.git dnsproxy.git > $ cd dnsproxy.git > $ go build > $ file dnsproxy > dnsproxy: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically > linked, Go > BuildID=6mIriY-h59Wwm2_gwbk2/rXhgRt_o3oIf_KSuKKtt/BYmwRfWtoqym2xPocRBT/Z2CIkEn5HaeVqVhdwxYu, > not stripped > > > As you can see, the compiled dnsproxy with the completely static go compiler > binary will also generate a static go program. I'm not sure if this is always > true. Any hints will be highly appreciated.
Whether the go tool itself is statically linked does not affect whether a Go program will be statically linked. However, the setting of "CGO_ENABLED" that is used when building the Go toolchain will become the default value of CGO_ENABLED when using that Go toolchain. That may be what is causing the effect that you are seeing. To build a dynamically linked program, try setting CGO_ENABLED=1 in the environment when running the go tool. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWZ3fgGUNZR45T3OCvuPcgsQi8-H%2BYa9dqOgFqaUXrZmA%40mail.gmail.com.