golang 跨平台编译——go 在windows上编译Linux平台的程序(Cross Compilation from Windows to Linux/Ubuntu)
Go Cross Compilation from Windows to Linux/Ubuntu
I have GO 1.7 installed on my Windows 10. I created test program and it works perfectly in Windows. Next step is to try to run it on my docker virtual machine with Ubuntu.
Answer:
That other question is a bit old (from 2013).
Cross-platform support evolved a lot, all you need to do is change the environment variables (GOARCH and GOOS) and run go build.
Navigate to the folder of the main package, then:
set GOARCH=amd64
set GOOS=linux
go build
You may change the name of the result binary like this:
go build -o "myapp"
Note that in Linux to compile the app for Windows amd64, a single command is enough (in the folder of the main package):
GOOS=windows GOARCH=amd64 go build
This is also confirmed in blog post: Dave Cheney: Cross compilation with Go 1.5:
To cross compile a Go program using Go 1.5 the process is as follows:
set
GOOSandGOARCHto be the values for the target operating system and architecture.run
go build -v YOURPACKAGE
Notes
You don't have to, and you shouldn't run go install, as that will compile and install the packages in your GOPATH, which is often not wanted. Doing cross compilation is not for developing / testing your app and packages. It is to produce a single binary which you will run on another system / computer.
go build will not install anything, it will just produce the executable binary. For details, see What does go build build?
Also confirmed in blog post: Dave Cheney: Cross compilation with Go 1.5:
When cross compiling, you should use
go build, notgo install. This is the one of the few cases wherego buildis preferable togo install.The reason for this is
go installalways caches compiled packages,.afiles, into thepkg/directory that matches the root of the source code.
golang 跨平台编译——go 在windows上编译Linux平台的程序(Cross Compilation from Windows to Linux/Ubuntu)的更多相关文章
- 在Mac/Linux/Windows上编译corefx遇到的问题及解决方法
这两天尝试在Mac/Linux/Windows三大平台上编译.NET跨平台三驾马车(coreclr/corefx/dnx)之一的corefx(.NET Core Framework),结果三个平台的编 ...
- [ZZ] 在windows上编译Mesa3d opengl32库
在windows上编译Mesa3d opengl32库 cheungmine http://blog.csdn.net/ubuntu64fan/article/details/8061475 Mesa ...
- 利用openssl管理证书及SSL编程第2部分:在Windows上编译 openssl
利用openssl管理证书及SSL编程第2部分:在Windows上编译 openssl 首先mingw的环境搭建,务必遵循下文: http://blog.csdn.net/ubuntu64fan/ar ...
- 在windows上编译wireshark源代码
终于在windows上成功编译了wireshark源代码,个中酸辛,都是泪..只能说要多试! windows上编译wireshark共用到三个东西:wireshark源代码.python.cygwin ...
- 在windows 上编译部署Rap2
在windows 上编译部署Rap2 引言 安装需要的环境 安装后端站点 创建数据库 在全局安装pm2 和 typescript 配置mysql,redis 数据库链接配置 初始化 编译 初始化数据库 ...
- 使 IIS 6.0 可以在 64 位 Windows 上运行 32 位应用程序 试图加载格式不正确的程序。
原文 使 IIS 6.0 可以在 64 位 Windows 上运行 32 位应用程序 试图加载格式不正确的程序. win7 64位操作系统上边运行IIS网站应用的时候,提示错误"试图加载格式 ...
- Windows上安装配置SSH教程(2)——在Windows XP和Windows 10上安装并配置OpenSSH for Windows
知识点汇总:http://www.cnblogs.com/feipeng8848/p/8559803.html ------------------------ 安装方式有3种: (1)Windows ...
- 在windows上编译MatConvNet
有个BT的要求,在windows上使用MatConvNet,并且需要支持GPU. 费了些力气,记录一下过程(暂不支持vl_imreadjpeg函数) 在这里下载MatConvNet,机器配置vs201 ...
- 如何在 Windows上编译Objective-C
Objective-C现在几乎已经变成了苹果的专利了,可以直接在苹果的Xcode上编译Objective-C程序,但是在Windows平台下的编译工具就寥寥无几了,本身这种语言用的人就不是很多.今天在 ...
随机推荐
- Farseer.net轻量级ORM开源框架 V1.x 入门篇:数据库上下文
导航 目 录:Farseer.net轻量级ORM开源框架 目录 上一篇:Farseer.net轻量级ORM开源框架 V1.x 入门篇:数据库配置文件 下一篇:Farseer.net轻量级ORM开源 ...
- BotFramework学习-01
微软在Build2016大会上表示,未来将是一个充满聊天机器人的世界,为此他们推出了微软Bot Framework,能够允许任何人制作自己的聊天机器人,微软则提供“cognitive microser ...
- matlab中数据类型
在MATLAB中有15种基本数据类型,分别是8种整型数据.单精度浮点型.双精度浮点型.逻辑型.字符串型.单元数组.结构体类型和函数句柄.这15种基本数据类型具体如下. 有符号整数型:int8,int1 ...
- oauth 理解
单点登录 对授权码模式的解读. 1. 用户访问客户端,客户端将请求认证服务器. 2. 用户选择是否给予客户端授权 3.用户授权后,认证服务器将用户导向客户端事先定义好的重定向的地址,同时会附上一个授权 ...
- 下载GitHub指定目录的文件
使用网站 https://minhaskamal.github.io/DownGit/#/home
- Dynamic Web Module版本对应tomcat版本
MyEclipse2017+JDK 1.8环境下 Dynamic Web Module版本3.1要对应tomcat7.0以上版本,不然部署项目时会出现错误(会出现无法部署项目的情况). Dynamic ...
- babun
Table of Contents 1. 环境 2. 检查/更新 3. 包管理 4. 版本管理 Git 4.1. 设置姓名邮箱(全局方式) 4.2. 添加 SSH 4.3. 链接测试 4.4. 权 ...
- 18mybatis
18mybatis-2018/08/02 1.mybatis标签 定义SQL语句 id :唯一的标识符 parameterType:传给此语句的参数的全路径名或别名例:com.test.poso.Us ...
- GNU编译器学习 --> 如何链接外部库【Linking with external libraries】
库也就是我们常说的library,一个库是若干个已经编译过的目标文件(.obj)的集合,它可以被链接到程序里.那么我们最常见的使用就是,我们在编程时会调用一些函数,这些函数别人已经写好了,它就放在库里 ...
- linux学习系列博客地址汇总
2018-09-28 16:03:43 CentOS7 yum命令:这是一个用来管理rpm包进行自动化安装的C/S模式的一个程序. CentOS7(无图形界面)支持中文显示的办法:系统安装好之后,有可 ...