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

在尝试使用gobuild编译hello.go时遇到`go.mod file not found in current directory or any parent directory`错误。原来,gobuild默认在当前目录下编译,需确保在包含go.mod的正确目录执行,或者指定包名。正确做法是切换到hello.go所在目录或设置GOPATH后再运行gobuild。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值