go build命令详解
生活随笔
收集整理的這篇文章主要介紹了
go build命令详解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
go help build
構建編譯由導入路徑命名的包,以及它們的依賴關系,但它不會安裝結果.
使用
go build [-o 輸出名] [-i] [編譯標記] [包名]如果參數為***.go文件或文件列表,則編譯為一個個單獨的包。
當編譯單個main包(文件),則生成可執行文件。
當編譯單個或多個包非主包時,只構建編譯包,但丟棄生成的對象(.a),僅用作檢查包可以構建。
當編譯包時,會自動忽略'_test.go'的測試文件。
參數
-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 raceor, if set explicitly, has _race appended to it. Likewise for the -msanflag. Using a -buildmode option that requires non-default compile flagshas 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>'.以上命令,單引號/雙引號均可。
對包的操作'go help packages'
對路徑的描述'go help gopath'
對 C/C++ 的互操作'go help c'
注意
構建遵守某些約定('go help gopath'),但不是所有的項目都遵循這些約定,當使用自己的慣例或使用單獨的軟件構建系統時可以選擇使用較低級別的調用go tool compile和go tool link來避免一些構建工具的開銷和設計決策
總結
以上是生活随笔為你收集整理的go build命令详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PowerShell: 详解Window
- 下一篇: Nomad技术手册:调度(Schedul