windows 上的 golang:如何为 Linux 构建?
golang on windows: How to build for Linux?
如何在 windows 上为 Linux 编译一个 go file/project?
在 Linux 上,应该可以通过一条线:
GOOS=windows go build -o filename.exe codefile.go
我通过 Powershell 尝试了类似的操作,但在我的 Linux 服务器 (Ubuntu 16.04 amd64) 上只出现了一个错误:
-bash: ./gotest: cannot execute binary file: Exec format error".
我尝试使用用户 Env-vars 为 GOOS = linux
和 GOARCH = amd64
以及通过 set GOOS = linux
在 Powershell 中,但我对 Powershell 了解不够 - go build 命令运行时没有错误并生成文件。
任何人都可以使用 go-1.10 通过 Powershell(或 cmd)(通过 VS 代码)解释 windows (10 1709 x64) 的一般操作方法吗?
使用 git bash 如果你的机器上安装了它并执行下面的命令
env GOOS=linux go build -o filename
您可以通过以下方式设置整个命令会话的执行操作系统:
set GOOS=linux
go build -o filename
它在相同的 Windows 10 版本上对我有用,并且在 Ubuntu 16.04 LTS
上运行流畅
如何在 windows 上为 Linux 编译一个 go file/project?
在 Linux 上,应该可以通过一条线:
GOOS=windows go build -o filename.exe codefile.go
我通过 Powershell 尝试了类似的操作,但在我的 Linux 服务器 (Ubuntu 16.04 amd64) 上只出现了一个错误:
-bash: ./gotest: cannot execute binary file: Exec format error".
我尝试使用用户 Env-vars 为 GOOS = linux
和 GOARCH = amd64
以及通过 set GOOS = linux
在 Powershell 中,但我对 Powershell 了解不够 - go build 命令运行时没有错误并生成文件。
任何人都可以使用 go-1.10 通过 Powershell(或 cmd)(通过 VS 代码)解释 windows (10 1709 x64) 的一般操作方法吗?
使用 git bash 如果你的机器上安装了它并执行下面的命令
env GOOS=linux go build -o filename
您可以通过以下方式设置整个命令会话的执行操作系统:
set GOOS=linux
go build -o filename
它在相同的 Windows 10 版本上对我有用,并且在 Ubuntu 16.04 LTS
上运行流畅