Golang 条件编译 [英] Golang conditional compilation
本文介绍了Golang 条件编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Go 1 中的条件编译方面遇到了问题.
I've got a trouble with conditional compilation in Go 1.
这是我的测试代码.我对//+build"约束和-tags"标志有什么误解吗?
Here is my test code. Is there anything I misunderstand about the "// +build" constraint and the "-tags" flag?
main1.go
// +build main1
package main
import (
"fmt"
)
func main() {
fmt.Println("This is main 1")
}
main2.go
// +build main2
package main
import (
"fmt"
)
func main() {
fmt.Println("This is main 2")
}
运行go build"时,我仍然遇到编译错误
when running "go build", I still got compile error
$ go build -tags 'main1'
# test
./main2.go:8: main redeclared in this block
previous declaration at ./main1.go:8
推荐答案
你必须在 //+build XXX
后面加一个空行.
You must follow // +build XXX
with a blank line.
在我的简短搜索中,我找不到记录在哪里/是否记录.但是 来源 明确指出
In my brief search, I couldn't find where/if this is documented. But the source clearly calls it out
这篇关于Golang 条件编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文