linker flags
Options passed to the Go linker through go build -ldflags, commonly used to strip debugging symbols or stamp a version into the binary.
In more detail
The linker is the last build step, which joins compiled packages into one binary. -ldflags="-s -w" removes the symbol table and debug information, making the file smaller. -X can set a string variable at build time, such as a version number.
Example
go build -trimpath -ldflags="-s -w" -o app .Related terms
- go build — The go subcommand that compiles a package and its dependencies into an executable file and prints nothing when it succeeds.
- -trimpath — A go build flag that removes the folder paths of your machine from the compiled binary.
- reproducible build — A build that produces the same result every time from the same inputs.
Taught in
- Building Static Binaries — Concurrent Systems Programming with Go