go study notes (b): go Language Work Area

The article introduces the language development environment to build a go, we introduce the workspace go language. In the language of the environment go build process, the need to understand the three environment variables:

1) GOROOT: go language installation root directory, in the previous article: D: \ Program Files \ go

2) GOPATH: their definition of workspace

Path generating executable: 3) GOBIN

GOPATH is the most complex of an environment variable. GOPATH is the directory path to multiple workspace. These paths language source code files go to store, archive and compiled executable file. To understand this concept, we need to understand the following three knowledge:

1. Source organization

Java with similar language has also been installed go code package as a unit, code package may have sub-packages. Before using the program entity needs to be imported to the program code package. Import path is the subdirectory from the src directory to store the actual program. go on general language source package GOPATH a workspace contained in the src directory of a sub-package.

2. The source installation Results

After installation If an archive, which is .a file (generated static files compiled), will be stored in the pkg directory, if you had an executable file will be stored in the bin directory of the workspace. For example, a directory structure is as follows:

After src / a / b / c, execution go install src / a / b / c, is generated archive pkg / a / b / ca.

So in a workspace, src, pkg, bin directory is a three-level flat. As shown below:

3.go installation and construction

Building codes and the installation of the package will be executed compilation, packaging and other operations, and any files generated by these operations will first be saved to a temporary directory.

1) constructing a command: go build

If you build the library source files, the result file will only exist in the temporary directory. The main building is to check and verify. If the build command source files, the result file will be transported to the directory where the source file is located.

2) the installation command: go install

Installation operation will first perform a build, operate and will be linked, and the results of the transport files to the specified directory.

If you are installing the library source files, the result file will be transported to its pkg directory in a subdirectory of the workspace.

If you are installing the command source files, the result file will be transported to it in the bin directory of the workspace, or environment variables to point GOBIN directory.

Published 33 original articles · won praise 2 · views 40000 +

Guess you like

Origin blog.csdn.net/zjj2006/article/details/104886942