snippetbashTip
go build — Compile Go sources. More information: <https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependenci
Viewed 0 times
httpscommandgo buildcompilecliinformationsourcesmore
Problem
How to use the
go build command: Compile Go sources. More information: <https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies>.Solution
go build — Compile Go sources. More information: <https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies>.Compile a 'package main' file (output will be the filename without extension):
go build {{path/to/main.go}}Compile, specifying the output filename:
go build -o {{path/to/binary}} {{path/to/source.go}}Compile a package:
go build -o {{path/to/binary}} {{path/to/package}}Compile a main package into an executable, enabling data race detection:
go build -race -o {{path/to/executable}} {{path/to/main_package}}Code Snippets
Compile a 'package main' file (output will be the filename without extension)
go build {{path/to/main.go}}Compile, specifying the output filename
go build -o {{path/to/binary}} {{path/to/source.go}}Compile a package
go build -o {{path/to/binary}} {{path/to/package}}Compile a main package into an executable, enabling data race detection
go build -race -o {{path/to/executable}} {{path/to/main_package}}Context
tldr-pages: common/go build
Revisions (0)
No revisions yet.