在Mac上为离线的Windows计算机创建gopls.exe。

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

Create gopls.exe for offline Windows computer on a Mac

问题

我正在尝试在我的离线Windows电脑上使用Visual Studio Code设置Go。我已经成功安装了VS Code、Go等,但在安装Go工具时遇到了问题。不幸的是,让我的Windows电脑联网不是一个选择。

对我来说,最重要的工具是gopls,它是Go语言服务器工具,提供悬停、自动完成等功能,可以大大提高生产效率。

我尝试了各种方法,包括:

  • 从我的联网Mac上将$GOROOT/bin/gopls的二进制文件复制到Windows上。
  • 克隆gopls的Github仓库,并按照这里所述,在Windows上重新构建gopls,运行go build -o gopls.exe main.go

然而,我遇到了以下错误:

无法启动客户端gopls

将克隆的仓库复制到我的离线电脑上并运行go install并不起作用,因为还需要其他依赖项来完全构建和安装gopls

另一个工具staticcheck这里为所有平台提供了预编译的二进制文件。

我有两个问题:

  1. 是否有一个公开可用的仓库/镜像/网站,提供用于Windows的主要Go工具的现成可下载的二进制文件?

  2. 是否有一种方法可以为Windows操作系统构建Go工具?

英文:

I am trying to set up Go on my offline Windows computer, using Visual Studio Code. I have successfully installed VS Code, Go, etc., but am running into trouble installing the Go tools. Unfortunately putting my Windows computer online isn't an option.

The most important tool for me is gopls the Go Language Server tool that provides hover, autocomplete, etc., and will really boost productivity.

I have tried various things, including:

  • Copying the binary file from $GOROOT/bin/gopls from my Internet-connected Mac to Windows.
  • Cloning the gopls repo from Github and rebuilding gopls for Windows as covered here by running go build -o gopls.exe main.go.

However I get the following error:

> Couldn't start client gopls

Copying the cloned repo to my offline computer and running go install does not work as there are other dependencies needed to fully build and install gopls.

Another tool, staticcheck, provides precompiled binaries for all platforms here.

I have two questions:

  1. Is there a publicly available repo/mirror/site that provides ready-made, downloadable binaries for the main set of Go tools for Windows?

  2. Is there a way that the Go tools can be built for a Windows OS?

答案1

得分: 0

这个问题的错误在于没有正确设置环境变量。

具体步骤如下:

  1. 浏览到你的Go源代码目录:$GOPATH/src/golang.org/x/

  2. 克隆Go工具库:git clone https://github.com/golang/tools.git

  3. 进入tools/gopls目录。

  4. 运行GOOS=windows GOARCH=386 go build -o gopls.exe main.go来编译一个在Windows上兼容的gopls二进制文件。

  5. 对于每个你需要安装的工具,重复步骤3和4。

参考:https://github.com/golang/go/wiki/WindowsCrossCompiling

英文:

The bug on this was setting the environment variable correctly.

To give exact steps:

  1. Browse to your Go src directory: $GOPATH/src/golang.org/x/

  2. Clone Go tools repo: git clone https://github.com/golang/tools.git

  3. cd tools/gopls.

  4. Run GOOS=windows GOARCH=386 go build -o gopls.exe main.go to compile a binary file for gopls that is compatible on Windows.

  5. Repeat steps 3 and 4 for each tool you need to install.

Ref: https://github.com/golang/go/wiki/WindowsCrossCompiling

huangapple
  • 本文由 发表于 2021年7月24日 07:53:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/68505986.html
匿名

发表评论

匿名网友

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

确定