英文:
go conditional compilation problem
问题
我有两个文件,production_constants.go和local_constants.go,它们在同一个包中。
在每个文件的顶部,我有以下内容:
// +build production
package receivers
和
// +build local
package receivers
当我使用任何一个标签进行编译(例如"go install -tags local"),两个标签都使用相同的常量(即编译标签没有被尊重)。如果我删除构建头部,奇怪的是一切仍然可以编译,并且使用相同的常量。只有当我删除包声明上方的所有空格("package receivers")时,我才会收到"___在此块中重新声明"的错误。
我感到困惑,因为我认为我已经按照文档中指示的条件构建包的方式做了。我是否漏掉了一些明显的东西?
英文:
I have two files, production_constants.go and local_constants.go in the same package.
At the top of each I have:
// +build production
package receivers
and
// +build local
package receivers
When I compile with either tag ("go install -tags local", for example) The same constants are used for either tag (ie the compile tags aren't respected). If I remove the build headers, weirdly everything still compiles and the same constants are used. Only when I remove all of the space above the package declaration ("package receivers") do I receive the "___ redeclared in this block".
I'm confused as I think I've done exactly what the documentation has indicated for a conditionally built package. Am I missing something obvious here?
答案1
得分: 1
你可以通过以下方式检查是否存在编译问题(如此线程中所提到的):
go clean -i receivers
# 或者
go install -a -tags local
通过强制对所有文件进行完整重新编译,标签应该会起作用。
英文:
You can check if this is a compilation issue (as mentioned in this thread) with:
go clean -i receivers
# or
go install -a -tags local
By forcing a full recompilation of every files, the tags should work.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论