We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go version
go version go1.6.3 linux/amd64
go env
GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/spotter/gocode" GORACE="" GOROOT="/usr/lib/go-1.6" GOTOOLDIR="/usr/lib/go-1.6/pkg/tool/linux_amd64" GO15VENDOREXPERIMENT="1" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0" CXX="g++" CGO_ENABLED="1"
compiling a project that includes cgo files, hence would normally make a dynamic linked binary (against C runtime) and then compiles it statically.
i.e.
go build ./path/to/command.go
vs
go build --ldflags '-extldflags "-static"' ./path/to/command.go
I expected the dynamic binary to be smaller than the fully statically linked binary.
the statically linked binary was significantly smaller, and I'm not the only one to see this
see this from reddit where someone sees similar behavior
https://www.reddit.com/r/golang/comments/46gbdz/binary_sizes_in_go/d058h1u/
The text was updated successfully, but these errors were encountered:
For questions about Go, see https://golang.org/wiki/Questions.
It looks like you're not comparing dynamic vs static, but dynamic vs static+stripped.
Sorry, something went wrong.
Stripped is even smaller (similar) in both cases.
Full Example
$ go build ./cmd/cmd.go $ ls -l cmd -rwxr-xr-x 1 spotter spotter 87322360 Dec 28 11:58 cmd $ strip cmd $ ls -l cmd -rwxr-xr-x 1 spotter spotter 60697704 Dec 28 11:58 cmd
$ go build --ldflags '-extldflags "-static"' ./cmd/cmd.go $ ls -l cmd -rwxr-xr-x 1 spotter spotter 70021544 Dec 28 11:59 cmd $ strip cmd $ ls -l cmd -rwxr-xr-x 1 spotter spotter 42909128 Dec 28 12:00 cmd
No branches or pull requests
What version of Go are you using (
go version
)?go version go1.6.3 linux/amd64
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/spotter/gocode"
GORACE=""
GOROOT="/usr/lib/go-1.6"
GOTOOLDIR="/usr/lib/go-1.6/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
What did you do?
compiling a project that includes cgo files, hence would normally make a dynamic linked binary (against C runtime) and then compiles it statically.
i.e.
go build ./path/to/command.go
vs
go build --ldflags '-extldflags "-static"' ./path/to/command.go
What did you expect to see?
I expected the dynamic binary to be smaller than the fully statically linked binary.
What did you see instead?
the statically linked binary was significantly smaller, and I'm not the only one to see this
see this from reddit where someone sees similar behavior
https://www.reddit.com/r/golang/comments/46gbdz/binary_sizes_in_go/d058h1u/
The text was updated successfully, but these errors were encountered: