2015-11-10 16:05

Go build会忽略文件而不会说什么


I'm getting some really strange behavior when attempting to build a windows version of my go program.

My directory contains:


Windows builds are failing because the build ignores foo_windows.go, for some reason. Note, there are no // +build comments in any files. 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. 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.

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.

Does anyone have any idea why this is happening?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongshao1981 dongshao1981 6年前

    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. 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. Setting CGO_ENABLED=1 included the file in the build.

    点赞 评论 复制链接分享