dougua3705 2014-12-09 00:09
浏览 208
已采纳

是什么导致“进行构建”失败并显示“输入中发生意外的NUL”?

I have a Linux VM where I am trying to compile a simple Go package. The package was retrieved into my user directory with git:

$ git clone [...]/test.go
Cloning into 'test.go'...
done.
$ cd test.go/
$ ls
main.go

I set up the GOPATH and build:

$ export GOPATH=$PWD; echo $GOPATH
/home/vagrant/test.go
$ go build
$ ls
main.go test.go*

So far so good. But now when I try to build again, it fails:

$ go build
can't load package: package .: read /home/vagrant/test.go/test.go: unexpected NUL in input

Deleting the test.go file before building will allow it to build. But this is inconvenient because tools like github.com/codegangsta/gin which try to rebuild the package will fail.

  • 写回答

1条回答 默认 最新

  • doulan4371 2014-12-09 00:09
    关注

    The repository was named [...]/test.go, and the default container directory for git clone is the repo name, so the containing directory is named test.go\.

    From go help build:

    If the package is main and file names are provided, the file name derives from the first file name mentioned, such as f1 for 'go build f1.go f2.go'; with no files provided ('go build'), the output file name is the base name of the containing directory.

    In this case the output is a file called test.go. The problem is:

    In the directory containing the package, .go, .c, .h, and .s files are considered part of the package

    During a go build if the output from a previous build, test.go, exists, it will be treated as a source file, triggering the 'unexpected NUL in input' message.

    The problem can be resolved by renaming the directory to avoid the build output having a name that will be considered part of the package.

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

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)