常用命令使用:
go help build
參數
-o
output 指定編譯輸出的名稱,代替默認的包名。
-i
install 安裝作為目標的依賴關系的包(用於增量編譯提速)。
以下 build 參數可用在 build, clean, get, install, list, run, test
-a 完全編譯,不理會-i產生的.a文件(文件會比不帶-a的編譯出來要大?) -n 僅打印輸出build需要的命令,不執行build動作(少用)。 -p n 開多少核cpu來並行編譯,默認為本機CPU核數(少用)。 -race 同時檢測數據競爭狀態,只支持 linux/amd64, freebsd/amd64, darwin/amd64 和 windows/amd64. -msan 啟用與內存消毒器的互操作。僅支持linux / amd64,並且只用Clang / LLVM作為主機C編譯器(少用)。 -v 打印出被編譯的包名(少用). -work 打印臨時工作目錄的名稱,並在退出時不刪除它(少用)。 -x 同時打印輸出執行的命令名(-n)(少用). -asmflags 'flag list' 傳遞每個go工具asm調用的參數(少用) -buildmode mode 編譯模式(少用) 'go help buildmode' -compiler name 使用的編譯器 == runtime.Compiler (gccgo or gc)(少用). -gccgoflags 'arg list' gccgo 編譯/鏈接器參數(少用) -gcflags 'arg list' 垃圾回收參數(少用). -installsuffix suffix ??????不明白 a suffix to use in the name of the package 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, has _race appended to it. Likewise for the -msan flag. Using a -buildmode option that requires non-default compile flags has a similar effect. -ldflags 'flag list' '-s -w': 壓縮編譯后的體積 -s: 去掉符號表 -w: 去掉調試信息,不能gdb調試了 -linkshared 鏈接到以前使用創建的共享庫 -buildmode=shared. -pkgdir dir 從指定位置,而不是通常的位置安裝和加載所有軟件包。例如,當使用非標准配置構建時,使用-pkgdir將生成的包保留在單獨的位置。 -tags 'tag list' 構建出帶tag的版本. -toolexec 'cmd args' ??????不明白 a program to use to invoke toolchain programs like vet and asm. For example, instead of running asm, the go command will run 'cmd args /path/to/asm <arguments for asm>