我有一个围棋程序test.go
package main
import "fmt"
var DEBUG_MODE bool = true
func main() {
fmt.Println(DEBUG_MODE)
}我想将编译时间上的编译变量设置为false
我试过:
go build -ldflags "-X main.DEBUG_MODE 0" test.go && ./test
true
kyz@s497:18:49:32:/tmp$ go build -ldflags "-X main.DEBUG_MODE false" test.go && ./test
true
kyz@s497:18:49:41:/tmp$ go build -ldflags "-X main.DEBUG_MODE 0x000000000000" test.go && ./test
true 它不工作,但当DEBUG_MODE是一个string时,它可以工作
发布于 2014-12-03 12:03:22
只能使用-X链接器标志设置字符串变量。从医生那里
-X importpath.name=value
Set the value of the string variable in importpath named name to value.
Note that before Go 1.5 this option took two separate arguments.
Now it takes one argument split on the first = sign.您可以使用字符串代替:
var DebugMode = "true"然后
go build -ldflags "-X main.DebugMode=false" test.go && ./testhttps://stackoverflow.com/questions/27271094
复制相似问题