The go build Tool
The go build
tool takes Go source code and compiles it so it can be executed. When creating software, you write code in a human-readable programming language. Then, the code needs to be translated into a machine-readable format to execute. This is done by a compiler that compiles the machine instructions from the source code. To do this with Go code, you would use go build
.
Exercise 17.01: Using the go build Tool
In this exercise, you will learn about the go build
tool. This will take your Go source code and compile it into a binary. To use it, run the go build
tool on the command line, as follows:
go build -o name_of_the_binary_to_create source_file.go
Let's get started:
- Create a new directory called
Exercise17.01
on your GOPATH. Within that directory, create a new file calledmain.go
: - Add the following code to the file to create a simple
Hello World
program:package main import "fmt" func main() { fmt.Println("...