简体   繁体   中英

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.

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. 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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