Home > front end >  Why doesn't `go run` leave behind the produced binary instead of deleting it?
Why doesn't `go run` leave behind the produced binary instead of deleting it?

Time:03-21

From what I understand, go run creates a binary, runs it, and then deletes it. Why delete it? Doesn't it mean that when running go run again, everything will need to be done again even if nothing has changed?

For the record, cargo run (for Rust) doesn't delete the binary.

What was the reasoning behind deleting the binary from the perspective of the language designers?

CodePudding user response:

go run does what you asked it to, runs the code. I wouldn’t want it leaving binaries around my file system every time I run some Go.

It doesn’t “delete the binary” so much as a binary never existed. You didn’t ask for a binary.

It compiles the components and runs them. If you go run the same code a second time, it will not need to recompile, The compiled work is cached. go build will drop a binary for you.

  •  Tags:  
  • go
  • Related