【发布时间】:2017-06-26 08:31:11
【问题描述】:
我在 Windows 10 上安装了 GO 1.7。我创建了测试程序,它在 Windows 中完美运行。下一步是尝试使用 Ubuntu 在我的 docker 虚拟机上运行它。
我找到了here 一些关于如何做的信息
set GOARCH=amd64
set GOOS=linux
go tool dist install -v pkg/runtime
go install -v -a std
我在 cmd 中运行第 1 行和第 2 行,没有问题。在第 3 行我有一个错误
go tool dist: open C:\Go\src\pkg\runtime: The system cannot find the path specified.
我手动检查了这个文件夹,并且有一个仅适用于 windows 的运行时
问题是我可以在哪里以及如何为 linux 下载它?或者也许那是我正在做的完全错误的方式......
2017 年 9 月 2 日更新
我按照建议跑了
set GOARCH=amd64
set GOOS=linux
go build -o "myapp"
在我将此文件复制到共享文件夹后,将表单复制到另一个非共享文件夹(以避免here 描述的问题)并执行
root@7dd1655ae5db:/__notshared# ./myapp
bash: ./myapp: cannot execute binary file: Exec format error
下载文件包后检查我的文件
root@7dd1655ae5db:/__notshared# file myapp
myapp: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows
似乎在构建过程中没有创建 linux 可执行文件。
【问题讨论】:
-
我认为你不需要第三个命令,只需安装std(即
go install std)就足够了。
标签: go cross-platform