====== 'go build' flags and friends cheatsheet ====== ''go build [build flags] [packages]'' ===== flags ===== These flags are available in the ''go'' ''build'', ''clean'', ''get'', ''install'', ''list'', ''run'', and ''test'' commands. Not all of these commands support all the flags (e.g. ''go list -i'' would not make sense). ^ Flag ^ Role ^ | ''-a'' | Force rebuilding of packages that are already up-to-date. | | ''-asmflags '' | Set flags for the assembler. | | ''-buildmode '' | Set the build mode (exe, c-shared, c-archive, pie, plugin). | | ''-compiler '' | Set the compiler to use (gc, gccgo). | | ''-gcflags '' | Set flags for the Go compiler. | | ''-i'' | Install the package after building it. | | ''-ldflags '' | Set linker flags. | | ''-mod '' | Set the module download mode (readonly, vendor, mod). | | ''-o '' | Set the output file name (default is package name or current directory). | | ''-race'' | Enable data race detection. | | ''-tags '' | Set build tags. | | ''-trimpath'' | Remove all file system paths from the resulting binary. | | ''-v'' | Print the names of packages as they are compiled. | | ''-work'' | Print the name of the temporary work directory and keep it (for debugging). | ===== Common build tags ===== ^ Tag ^ Purpose ^ | ''netgo'' | Use pure Go networking libraries. | | ''osusergo'' | Use pure Go implementation for user lookup. | ===== Common linker flags ===== ^ Flag ^ Purpose ^ | ''-extld '' | Use a specific external linker. | | ''-s'' | Omit symbol table and debug information. | | ''-w'' | Omit DWARF debugging information. | ===== Build modes ===== ^ Build mode ^ Description ^ | ''c-archive'' | Build a C archive library. | | ''c-shared'' | Build a C shared library. | | ''exe'' | Build a standalone executable binary (default). | | ''pie'' | Build a position-independent executable. | | ''plugin'' | Build a Go plugin. |