Go错误:"fmt.Println未使用"。什么?

huangapple go评论68阅读模式
英文:

Go error: "fmt.Println not used". What?

问题

我遇到了一个错误:

fmt.Println未使用

这一行是我的源文件的最后一行。在那个文件中,我没有使用fmt包,但是我最近使用过。

当我尝试构建包或运行测试时会出现这个问题。

编辑:

如果我运行go clean myproject,我仍然会得到相同的响应。

我刚刚运行了go clean,现在有:

# myproject
<epoch>: fmt.Println未使用

为了方便Cat Plus Plus,这是一个触发错误的源文件:

types2.go

package mypackage

import (
)

运行:

go build mypackage
# mypackage
./types2.go:4: fmt.Println未使用

是的,你没看错。

英文:

What the title said. I'm getting an error:

fmt.Println not used

The line mentioned is the last line of my source file. I'm not using the fmt package in that file, but I did recently.

This happens when I try to build the package or run tests.

EDIT:

If I go clean myproject the project I still get the same response.

I ran just go clean and now have:

# myproject
&lt;epoch&gt;: fmt.Println not used

EDIT for the benefit of Cat Plus Plus, here's a source file triggering the error:

types2.go

package mypackage

import (
)

to run:

go build mypackage
# mypackage
./types2.go:4: fmt.Println not used

Yes you read that right.

答案1

得分: 2

答案是我在某个文件中使用了fmt.Println表达式。编译器告诉我错误发生在错误的文件中。更多信息请参考这篇博文。

http://blog.afandian.com/2012/07/strange-error-in-go-fmt-println-not-used/

英文:

The answer was that I had the expression fmt.Println in a file somewhere. The compiler told me that the error was occurring in incorrect file(s). More info in this blog post.

http://blog.afandian.com/2012/07/strange-error-in-go-fmt-println-not-used/

答案2

得分: 1

我怀疑你没有编译你认为你正在编译的东西。你的GOPATH是什么样的?请记住,go命令只会根据GOPATH来查找包,而不关心你当前的目录。另外,go build不会“运行”或者安装包,而Go clean也不像make clean那样只是清理--它实际上做了其他的事情。

英文:

I suspect you're not compiling what you think you're compiling. What does your GOPATH look like? Remember the go command just goes by GOPATH to find packages and doesn't care about your current directory. Also, go build doesn't "run" or even install packages and Go clean isn't like make clean--it really does something else.

huangapple
  • 本文由 发表于 2012年7月3日 04:34:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/11300795.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定