英文:
GO VSCode debugger not working on Apple with M1 Chip
问题
我可以运行Go文件,但无法在VSCode中进行调试。
错误信息:
"启动失败:无法启动进程:无法在Rosetta下运行,请检查安装的Go版本是否适合您的CPU架构"
英文:
I can run the go files, but I can't debug them in vscode.
Error:
"Failed to launch: could not launch process: can not run under Rosetta, check that the installed build of Go is right for your CPU architecture"
答案1
得分: 18
我在将我的苹果电脑升级到搭载 M1 芯片后也遇到了这个问题。有几个步骤可以用来诊断问题的根本原因。首先要检查你安装的 Go 版本。
> go version
go version go1.17.2 darwin/arm64
如果版本不是 darwin/arm64
,那么你安装的是错误的架构,适用于 M1 芯片的 Mac。这很容易发生,因为默认的架构是 darwin/amd64
。
如果是这个问题,卸载当前版本的 Go,然后安装位于这里的 arm64 版本:https://golang.org/dl/
安装完成后,需要验证两个环境变量:
在终端中执行以下命令:
> echo $GOOS
darwin
> echo $GOARCH
arm64
如果这些变量没有设置,可以导出它们。我建议将它们添加到你的 .zshrc 文件或等效文件中。
export GOOS=darwin
export GOARCH=arm64
最后,在 VS Code 中启动你的项目,并在命令栏中输入以下命令以重新安装所有 Go 工具:
cmd + shift + p
Go: Install/Update Tools
这样应该可以通过 VS Code 成功运行和调试了。
英文:
I ran into this as well after an upgrade to an Apple with an M1. There are several steps toward diagnosing the root cause of the issue. The first is to check the version of Go you've got installed.
> go version
go version go1.17.2 darwin/arm64
If the version is not darwin/arm64
you've installed the wrong architecture for a Mac with an M1 chip. This is easy to do, since the default is darwin/amd64
.
If this is the issue, uninstall your current version of go and install the arm64 equivalent located here: https://golang.org/dl/
Once the install is complete, it's time to verify two environment variables:
In a terminal:
> echo $GOOS
darwin
> echo $GOARCH
arm64
If these are not set, go ahead and export them. I'd recommend adding them to your .zshrc or your equivalent.
export GOOS=darwin
export GOARCH=arm64
Finally, in VS Code, launch your project and enter the command bar in order to re-install all of the Go: Install/Update tools:
cmd + shift + p
Go: Install/Update Tools
This should allow you to run and debug successfully through VS Code.
答案2
得分: 10
对于那些在Go中找不到"dlv"的人,以下是额外的答案:安装/更新工具
有两种解决方案:
-
从go/bin中删除"dlv" -> 重新打开VSCode -> 运行调试器 -> 从VSCode的通知中安装"dlv"
-
尝试使用以下命令手动更新:
go install -v github.com/go-delve/delve/cmd/dlv@latest
希望对你们有帮助
英文:
In additional answer to someone who don't see "dlv" in Go: Install/Update Tools
There're 2 solutions
-
Remove "dlv" from go/bin -> reopen VSCode -> Run debugger -> Install "dlv" from VSCode the notification
-
Try to update it manually by using
go install -v github.com/go-delve/delve/cmd/dlv@latest
Hope this help you guys
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论