1. 程式人生 > 實用技巧 >go build 引數

go build 引數

常用命令使用:

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>