控制臺編譯,少不了使用:go build,用法:
usage: go build [-o output] [-i] [build flags] [packages]
?????? 根據(jù)輸入的包之間的依賴性,編譯包,但并不會將編譯的結(jié)果進(jìn)行安裝。如果編譯的參數(shù)是一系列的*.go文件,build命令視這些文件在一個包中。當(dāng)編譯一個main包時,build命令會將編譯的可執(zhí)行結(jié)果放入第一個go文件名(無后綴.go)中(如:'go build ed.go rx.go' 編譯后的可執(zhí)行文件為'ed'或者'ed.exe‘,后者為windows系統(tǒng)的文件名 ),當(dāng)編譯的參數(shù)是一個目錄而不是一系列g(shù)o文件時,build命令生產(chǎn)的可執(zhí)行文件名為目錄名 ('go build unix/sam' writes 'sam' or 'sam.exe')。
當(dāng)編譯多個包或一個非main包時,build命令編譯包并丟棄編譯結(jié)果,只是檢查是否能夠被編譯。
當(dāng)編譯包時,build會忽略*_test.go文件;
-o參數(shù),只被允許在編譯一個單獨包時使用,并且強制將編譯的可執(zhí)行文件或object寫入戶名的文件名中。
-i參數(shù),安裝依賴于目標(biāo)的包
build flag在build、clean、get、install、list、run、test命令中通用。
? ? -a
? ? ? ? force rebuilding of packages that are already up-to-date.
? ? -n
? ? ? ? print the commands but do not run them.
? ? -p n
? ? ? ? the number of programs, such as build commands or
? ? ? ? test binaries, that can be run in parallel.
The build flags are shared by the build, clean, get, install, list, run,
and test commands:
? ? -a
? ? ? ? force rebuilding of packages that are already up-to-date.
? ? -n
? ? ? ? print the commands but do not run them.
? ? -p n
? ? ? ? the number of programs, such as build commands or
? ? ? ? test binaries, that can be run in parallel.
? ? ? ? The default is the number of CPUs available.
? ? -race
? ? ? ? enable data race detection.
? ? ? ? Supported only on linux/amd64, freebsd/amd64, darwin/amd64 and windows/amd64.
? ? -msan
? ? ? ? enable interoperation with memory sanitizer.
? ? ? ? Supported only on linux/amd64,
? ? ? ? and only with Clang/LLVM as the host C compiler.
? ? -v
? ? ? ? print the names of packages as they are compiled.
? ? -work
? ? ? ? print the name of the temporary work directory and
? ? ? ? do not delete it when exiting.
? ? -x
? ? ? ? print the commands.
針對-gcflags的值可使用go tool compile查看
The 'go build' and 'go install' commands take a -buildmode argument which
indicates which kind of object file is to be built. Currently supported values
are:
-buildmode=archive
Build the listed non-main packages into .a files. Packages named
main are ignored.
-buildmode=c-archive
Build the listed main package, plus all packages it imports,
into a C archive file. The only callable symbols will be those
functions exported using a cgo //export comment. Requires
exactly one main package to be listed.
-buildmode=c-shared
Build the listed main packages, plus all packages that they
import, into C shared libraries. The only callable symbols will
be those functions exported using a cgo //export comment.
Non-main packages are ignored.
-buildmode=default
Listed main packages are built into executables and listed
non-main packages are built into .a files (the default
behavior).
-buildmode=shared
Combine all the listed non-main packages into a single shared
library that will be used when building with the -linkshared
option. Packages named main are ignored.
-buildmode=exe
Build the listed main packages and everything they import into
executables. Packages not named main are ignored.
-buildmode=pie
Build the listed main packages and everything they import into
position independent executables (PIE). Packages not named
main are ignored.
-buildmode=plugin
Build the listed main packages, plus all packages that they
import, into a Go plugin. Packages not named main are ignored.