用AI赚第一桶💰低成本搭建一套AI赚钱工具,源码可二开。 广告
[TOC] ## 命令 ``` -a 强制重建已经更新的软件包 -n 打印命令,但不运行它们 -p n 指定构建时候cpu的核数.默认为当前cpu的核数 -race 启用数据竞争检测 -msan 使用内存清除器启用互操作。只支持Linux -v 打印出那些被编译时的代码包的名字 -work 打印出编译时生成的临时工作目录的路径,并在编译结束时保留它。 在默认情况下,编译结束时会删除该目录 -x 与-n 类似,但是会执行 -asmflags '[pattern=]arg list' 此标记可以后跟另外一些标记,如-D、-I、-S等。 这些后跟的标记用于控制Go语言编译器编译汇编语言文件时的行为 -buildmode mode 指定编译模式,"go help buildmode"查看更多 -compiler name 要使用的编译器的名称,如在运行时。编译器( "gccgo"或 "gc") -gccgoflags '[pattern=]arg list' 指定需要传递给gccgo编译器或链接器的标记的列表 -gcflags '[pattern=]arg list' 指定需要传递给go tool compile命令的标记的列表 -ldflags '[pattern=]arg list' 指定需要传递给go tool link命令的标记的列表 -linkshared 此标记用于与-buildmode=shared一同使用 在此之上进行链接操作 -mod mode module 下载模式: (readonly, vendor, or mod.) 通过 'go help modules' 查看更多 -pkgdir dir 指定一个目录,并从改目录下加载编译好的.a 文件, 并把编译可能产生新的 .a 文件放入到该目录中 -tags tag,list 指定在实际编译期间需要受理的编译标签(也可被称为编译约束)的列表 -trimpath -toolexec 'cmd args' 去自定义在编译期间使用一些Go语言自带工具(如vet、asm等)的方式 ``` ## 实例 ### -race 查看数据竞争 ### 不出现dos窗口 ``` go build -ldflags="-H windowsgui" one.go -H 程序从后台运行,不出现dos窗口 ``` ### 检查边界 <details> <summary>main.go</summary> ``` package main func f1(s []int) { _ = s[0] // line 5: bounds check _ = s[1] // line 6: bounds check _ = s[2] // line 7: bounds check } func f2(s []int) { _ = s[2] // line 11: bounds check _ = s[1] // line 12: bounds check eliminated! _ = s[0] // line 13: bounds check eliminated! } func f3(s []int, index int) { _ = s[index] // line 17: bounds check _ = s[index] // line 18: bounds check eliminated! } func f4(a [5]int) { _ = a[4] // line 22: bounds check eliminated! } func main() {} ``` </details> <br/> 执行 ``` > go build -gcflags="-d=ssa/check_bce/debug=1" main.go ./example1.go:5: Found IsInBounds ./example1.go:6: Found IsInBounds ./example1.go:7: Found IsInBounds ./example1.go:11: Found IsInBounds ./example1.go:17: Found IsInBounds ``` ### 踪包init函数的消耗 ``` $go build $GODEBUG=inittrace=1 ./helloworld init internal/bytealg @0.006 ms, 0 ms clock, 0 bytes, 0 allocs init runtime @0.037 ms, 0.031 ms clock, 0 bytes, 0 allocs init errors @0.29 ms, 0.005 ms clock, 0 bytes, 0 allocs init math @0.31 ms, 0 ms clock, 0 bytes, 0 allocs init strconv @0.33 ms, 0.002 ms clock, 32 bytes, 2 allocs init sync @0.35 ms, 0.003 ms clock, 16 bytes, 1 allocs init unicode @0.37 ms, 0.10 ms clock, 24568 bytes, 30 allocs init reflect @0.49 ms, 0.002 ms clock, 0 bytes, 0 allocs init io @0.51 ms, 0.003 ms clock, 144 bytes, 9 allocs ... ```