第一次写helloword时遇到的问题。
在命令行执行go build 准备编译 hello.go 时 提示报错
go: go.mod file not found in current directory or any parent directory; see 'go help modules'
解决:
没有详细看过go build 命令的文档,理所应当的以为当使用go build 时会自动编译GOPATH目录下所有的.go文件。
但实际上当仅使用go build时意味着使用当前目录进行编译,所以产生上述问题。
正确用法需要转到hello.go目录下再执行,或在设置了GOPATH的条件下使用 "go build 包名"
在尝试使用gobuild编译hello.go时遇到`go.mod file not found in current directory or any parent directory`错误。原来,gobuild默认在当前目录下编译,需确保在包含go.mod的正确目录执行,或者指定包名。正确做法是切换到hello.go所在目录或设置GOPATH后再运行gobuild。

1万+

被折叠的 条评论
为什么被折叠?



