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

Taught in

References