This is a creation in Article, where the information may have evolved or changed.
Go help build
The build compiles the packages named by the import path, and their dependencies, but it does not install the results.
Use
go build [-o 输出名] [-i] [编译标记] [包名]
If the parameter is a ***.go file or a list of files, it is compiled into a separate package.
When a single main package (file) is compiled, the executable file is generated.
When compiling a single or multiple package non-primary package, only the build package is built, but the generated object (. A) is discarded, and only as a check package can be built.
The test file for ' _test.go ' is automatically ignored when the package is compiled.
Parameters
-O
output 指定编译输出的名称,代替默认的包名。
-I.
install 安装作为目标的依赖关系的包(用于增量编译提速)。
The following build parameters are available in build, clean, get, install, list, run, test
-a fully compiled, ignoring-I generated. A file (the file will be larger than the compilation without-a)? -N Prints only the command required for the output build and does not perform a build action (less). -P n the number of cores on the CPU to compile in parallel, default to native CPU cores (less). -race simultaneously detects the data race status, only supports LINUX/AMD64, FREEBSD/AMD64, DARWIN/AMD64, and Windows/amd64.-msan enable interoperability with the memory sterilizer. Only LINUX/AMD64 is supported, and only CLANG/LLVM is used as the host C compiler (less). -V prints out the compiled package name (less).-work prints the name of the temporary working directory and does not delete it when exiting (less). -X Prints the command name (-N) of the output execution (less).-asmflags ' Flag list ' passes the parameters of each Go tool asm call (less)-buildmode mode (less) ' Go help Buildmode ' -compiler name uses the compiler = = runtime. Compiler (GCCGO or GC) (less).-gccgoflags ' arg list ' GCCGO compile/linker parameters (less)-gcflags ' arg list ' garbage collection parameters (less).-installsuffix Suffix?????? Do not understand a suffix to use in the name of the installation directory, in order to keep output separate from default Builds. If using The-race flag, the install suffix is automatically set to race or, if set explicitly, have _race appended to I T. Likewise for The-msan flag. Using a-buildmode option that requires Non-default compile flags have a similar effect.-lDflags ' flag list '-s-w ': Compress compiled Volume-s: Remove symbol Table-W: Remove debug information, cannot gdb debug-linkshared link to a shared library created previously using-buildmode=shar Ed.-pkgdir dir installs and loads all packages from the specified location, not the usual location. For example, when building with a nonstandard configuration, use-pkgdir to leave the resulting package in a separate location. -tags ' tag list ' builds a version with tag.-toolexec ' cmd args '?????? Do not understand a program to the use of invoke toolchain programs like vet and ASM. For example, instead of running ASM, the GO command would run ' cmd args/path/to/asm <arguments for asm> '.
The above command, single or double quotation marks are available.
Operations on a package'go help packages'
Description of the path'go help gopath'
Interop for C/+ +'go help c'
Attention
Builds adhere to certain conventions ( 'go help gopath' ), but not all projects follow these conventions, and you can choose to use lower-level calls go tool compile and go tool link avoid the overhead and design decisions of some build tools when using your own routines or building systems with separate software
See Also:go install, go get, go clean.