简体   繁体   English

Go build忽略文件而不说任何话

[英]Go build ignores files without saying anything

I'm getting some really strange behavior when attempting to build a windows version of my go program. 在尝试构建我的go程序的Windows版本时,我遇到了一些非常奇怪的行为。

My directory contains: 我的目录包含:

foo.go  
foo_windows.go  
foo_windows_test.go  
foo_unix.go  
foo_linux.go  
foo_linux_test.go  
foo_darwin.go  

Windows builds are failing because the build ignores foo_windows.go, for some reason. Windows构建失败,因为构建忽略了foo_windows.go,出于某种原因。 Note, there are no // +build comments in any files. 请注意,任何文件中都没有// +build注释。 Here's the output of the build file list: 这是构建文件列表的输出:

$ GOOS=linux GOARCH=amd64 go list -f '{{.IgnoredGoFiles}}' github.com/foo/
[foo_darwin.go foo_windows.go foo_windows_test.go]

$ GOOS=darwin GOARCH=amd64 go list -f '{{.IgnoredGoFiles}}' github.com/foo/
[foo_linux.go foo_linux_test.go foo_windows.go foo_windows_test.go]

$ GOOS=windows GOARCH=amd64 go list -f '{{.IgnoredGoFiles}}' github.com/foo/
[foo_darwin.go foo_linux.go foo_linux_test.go foo_unix.go foo_windows.go]

Obviously the last item is very wrong. 显然最后一项是非常错误的。 foo_windows.go should not be ignored. foo_windows.go不应该被忽略。 Note that when including the methods in foo_windows.go in foo.go directly, the windows build succeeds, so it really is excluding the file, and the file contains everything needed for a good build. 请注意,当直接在foo_windows.gofoo.go foo_windows.go中的方法时,windows构建成功,因此它实际上是排除文件,并且该文件包含良好构建所需的所有内容。

Both cross-compiling on a mac and compiling normally on a windows machine lead to the same problems of file exclusion, which leads me to believe it's something about the file itself that is causing problems, but I'm not sure what it might be. 在Mac上进行交叉编译并在Windows机器上正常编译都会导致文件排除的相同问题,这使我相信文件本身会导致问题,但我不确定它可能是什么。

Does anyone have any idea why this is happening? 有谁知道为什么会这样?

I will answer my own question and hope it helps someone else. 我会回答我自己的问题,并希望它可以帮助别人。

foo_windows.go was not included in the build because of unexpressed build errors. 由于未出现的构建错误, foo_windows.go未包含在构建中。 Specifically, foo_windows.go contains C code, and because CGO_ENABLED=0 by default, go didn't try compiling it, it just saw there was C code in the file and excluded the file. 具体来说, foo_windows.go包含C代码,并且因为默认情况下CGO_ENABLED=0 ,所以go没有尝试编译它,它只是看到文件中有C代码CGO_ENABLED=0除了文件。 Setting CGO_ENABLED=1 included the file in the build. 设置CGO_ENABLED=1包含构建中的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM