英文:
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
在这里为所有平台提供了预编译的二进制文件。
我有两个问题:
-
是否有一个公开可用的仓库/镜像/网站,提供用于Windows的主要Go工具的现成可下载的二进制文件?
-
是否有一种方法可以为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 rebuildinggopls
for Windows as covered here by runninggo 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:
-
Is there a publicly available repo/mirror/site that provides ready-made, downloadable binaries for the main set of Go tools for Windows?
-
Is there a way that the Go tools can be built for a Windows OS?
答案1
得分: 0
这个问题的错误在于没有正确设置环境变量。
具体步骤如下:
-
浏览到你的Go源代码目录:
$GOPATH/src/golang.org/x/
-
克隆Go工具库:
git clone https://github.com/golang/tools.git
-
进入
tools/gopls
目录。 -
运行
GOOS=windows GOARCH=386 go build -o gopls.exe main.go
来编译一个在Windows上兼容的gopls二进制文件。 -
对于每个你需要安装的工具,重复步骤3和4。
参考:https://github.com/golang/go/wiki/WindowsCrossCompiling
英文:
The bug on this was setting the environment variable correctly.
To give exact steps:
-
Browse to your Go src directory:
$GOPATH/src/golang.org/x/
-
Clone Go tools repo:
git clone https://github.com/golang/tools.git
-
cd tools/gopls
. -
Run
GOOS=windows GOARCH=386 go build -o gopls.exe main.go
to compile a binary file for gopls that is compatible on Windows. -
Repeat steps 3 and 4 for each tool you need to install.
Ref: https://github.com/golang/go/wiki/WindowsCrossCompiling
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论