duanbin4847 2015-11-10 16:05
浏览 314
已采纳

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

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?

  • 写回答

1条回答 默认 最新

  • dongshao1981 2015-11-11 13:04
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?