Home  >  Article  >  How does Go language perform? Execution process introduction

How does Go language perform? Execution process introduction

青灯夜游
青灯夜游forward
2019-02-26 11:55:245746browse

What this article brings to you is how to execute Go language? The introduction to the execution process has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. [Video tutorial recommendation: Go tutorial]

Go execution process

1. If it is against the source After the code is compiled, then execute it. The execution flow of Go is as shown below

The executable file generated by go build will be in the current directory

2. If the go run source file operation is performed directly on the source code, the execution process of Go is as shown below

Two ways to execute the process Note

  1. If we compile and generate an executable file first, we can copy the executable file to a machine that does not have a go development environment and it can still run

  2. If we directly go run the source file, then if we want to run it on another machine, we also need a go development environment, otherwise it cannot be executed.

  3. When compiling, the compiler will include the library files since the program was run in the executable file, so the executable file becomes much larger.

Example:

go build index.go

go run index.go

go run, go build, go install command explanation

go run:go run compiles and runs the program directly. It will generate a temporary file (but will not generate an .exe file) and directly output the program execution results on the command line to facilitate user debugging.

go build:go build is used to test the compiled package. It mainly checks whether there are compilation errors. If it is the source code of an executable file (that is, the main package), it will be generated directly. An executable file.

go install: go install has two steps: the first step is to compile the imported package files. The main program will not be compiled until all imported package files are compiled; the second step is Place the compiled executable file in the bin directory ($GOPATH/bin) and the compiled package file in the pkg directory ($GOPATH/pkg)

The above is the detailed content of How does Go language perform? Execution process introduction. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete
Previous article:what python can doNext article:what python can do