我试图在Visual代码中安装Go工具,并在安装gopls时得到以下错误:
Tools environment: GOPATH=/Users/jal/go
Installing 1 tool at /Users/jal/go/bin in module mode.
gopls
Installing golang.org/x/tools/gopls@latest FAILED
{
"killed": false,
"code": 2,
"signal": null,
"cmd": "/opt/brew/bin/go install -v golang.org/x/tools/gopls@latest",
"stdout": "",
"stderr": "golang.org/x/tools/internal/fastwalk\n# golang.org/x/tools/internal/fastwalk\n../../go/pkg/mod/golang.org/x/tools@v0.2.1-0.20221101170700-b5bc717366b2/internal/fastwalk/fastwalk_darwin.go:11:10: fatal error: 'dirent.h' file not found\n#include <dirent.h>\n ^~~~~~~~~~\n1 error generated.\n"
}
1 tools failed to install.
gopls: failed to install gopls(golang.org/x/tools/gopls@latest): Error: Command failed: /opt/brew/bin/go install -v golang.org/x/tools/gopls@latest
golang.org/x/tools/internal/fastwalk
# golang.org/x/tools/internal/fastwalk
../../go/pkg/mod/golang.org/x/tools@v0.2.1-0.20221101170700-b5bc717366b2/internal/fastwalk/fastwalk_darwin.go:11:10: fatal error: 'dirent.h' file not found
#include <dirent.h>
^~~~~~~~~~
1 error generated.我知道我有dirent.h,因为我在运行find / -iregex ".*/dirent.h$" 2>/dev/null时在本地Xcode SDK中看到了结果。
我遵循以下步骤:https://learn.microsoft.com/en-us/azure/developer/go/configure-visual-studio-code
我的设计是:
在命令调色板中重新安装go.dev/doc/install
中选择”Go: install /Update“并选择
除gopls外,所有工具都已成功安装。我已经安装了go通过Homebrew,也安装了gopls通过Homebrew,但我不知道如何配置VSCode指向这个替代的gopls路径。
发布于 2022-11-10 18:46:16
这个问题似乎是由于Xcode和命令行工具配置错误或损坏造成的。
我从这里卸载和重新安装了最新版本的Xcode以及命令行工具包(这个包特别重要),https://developer.apple.com/download/all/。
尽管xcode-select --install告诉我所有安装都是正确的和最新的,但我还是不得不这样做。
未来的问题讨论可在这里获得:https://github.com/golang/go/issues/56663
https://stackoverflow.com/questions/74367673
复制相似问题