致命错误:在尝试通过Visual Studio Code安装gopls/Go工具时找不到’dirent.h’文件。

huangapple go评论114阅读模式
英文:

fatal error: 'dirent.h' file not found when trying to install gopls/Go tools via Visual Studio Code

问题

我正在尝试在Visual Studio Code中安装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

我的设置如下:

  • 通过Homebrew进行全新安装的go
  • 通过go.dev/doc/install进行全新安装的VSCode macOS
  • 安装Go插件
  • 在命令面板中,搜索并选择"Go: Install/Update tools",然后在下拉菜单中选择所有工具

除了gopls之外,所有工具都成功安装。我已经通过Homebrew安装了go,并且还通过Homebrew安装了gopls,但不确定如何配置VSCode以指向这个替代的gopls路径。

英文:

I am trying to install the Go tools in Visual Studio Code and am getting the following error when installing 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
{
 &quot;killed&quot;: false,
 &quot;code&quot;: 2,
 &quot;signal&quot;: null,
 &quot;cmd&quot;: &quot;/opt/brew/bin/go install -v golang.org/x/tools/gopls@latest&quot;,
 &quot;stdout&quot;: &quot;&quot;,
 &quot;stderr&quot;: &quot;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: &#39;dirent.h&#39; file not found\n#include &lt;dirent.h&gt;\n         ^~~~~~~~~~\n1 error generated.\n&quot;
}

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: &#39;dirent.h&#39; file not found
#include &lt;dirent.h&gt;
         ^~~~~~~~~~
1 error generated.

I know I have dirent.h because I see results in my local Xcode SDKs when running find / -iregex &quot;.*/dirent.h$&quot; 2&gt;/dev/null.

I am following the steps here: https://learn.microsoft.com/en-us/azure/developer/go/configure-visual-studio-code

My setup is:

  • Fresh install of go from Homebrew
  • Fresh install of VSCode macOS from go.dev/doc/install
  • Instal the Go plugin
  • In the Command Palette, search for and select "Go: Install/Update tools" and select all tools in the dropdown

All tools are installed successfully except for gopls. I have installed go via Homebrew and have also installed gopls via Homebrew but am not sure how to configure VSCode to point to this alternative gopls path.

答案1

得分: 1

问题似乎是由于配置错误或损坏的Xcode和命令行工具引起的。

我从这里https://developer.apple.com/download/all/卸载并重新安装了最新版本的Xcode,以及命令行工具包(这个特别重要)。

尽管xcode-select --install告诉我一切都安装正确且更新,但我还是不得不这样做。

有关未来问题讨论,请参阅此处:https://github.com/golang/go/issues/56663

英文:

The issue seemed to be due to a misconfigured or corrupted Xcode and command line tools.

I uninstalled and re-installed the latest version of Xcode, as well as the Command Line Tools package (this one is especially important) from here https://developer.apple.com/download/all/.

I had to do this despite xcode-select --install telling me everything was installed correctly and up to date.

Future issue discussion available here: https://github.com/golang/go/issues/56663

huangapple
  • 本文由 发表于 2022年11月9日 06:05:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/74367673.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定