In C, we can build a debug version or a release version of the binary files (the object files and the executable). How can we do this in Go?
To complete the list, go run compiles your application into a temporary folder, and starts that executable binary. When the app exits, it properly cleans up the temporary files.
This command does perform the exact operation as go build but places the binary in $GOPATH/bin` directory alongside the binaries of third-party tools installed via go get now if you run $GOPATH/bin/hello you will see Hello, world!
Go Binaries is an open-source server allowing non-Go users to quickly install tools written in Golang, without installing the Go compiler or a package manager — all you need is curl .
In Go, it isn't typical to have a debug version or a release version.
By default, go build
combines symbol and debug info with binary files. However, you can remove the symbol and debug info with go build -ldflags "-s -w"
.
You can instruct the linker to strip debug symbols by using
go install -ldflags '-s'
I just tried it on a fairly large executable (one of the GXUI samples), and this reduced it from ~16M to ~10M. As always, your mileage may vary...
Here is a full list of all linker options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With