windows环境下go build 报错 go: go.mod file not found in current directory or any parent directory

2022-06-21 12:05:39

第一次写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 包名"

  • 作者:isoyy
  • 原文链接:https://blog.csdn.net/isoyy/article/details/121638207
    更新时间:2022-06-21 12:05:39