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平台下的编译工具就寥寥无几了,本身这种语言用的人就不是很多.今天在 ...
随机推荐
- c#中out参数的作用
给你个简单的解释说法吧.虽然不完全对.但是我可以让你理解OUT有什么作用.呵呵 举个例子.每个方法只能有一个返回值.但是你想有多个返回值,呵呵.OUT就起作用了啊.比如分页,不光返回数据,还要返回总记 ...
- UI概念体系要素
结构.渲染.交互.数据. 要素.呈现.交互 1)UI(组成)要素:结构 2)布局: 3)渲染: 4)事件处理: 5)数据:
- linux查看内核版本和发行版本号
1.查看Linux内核版本号:1.1 uname -r #查看当前linux系统的内核版本号显示举例:2.6.21-1.3194.fc71.2 uname -a #可以查看包括内核版本号.机器硬件信息 ...
- ALTER DATABASE 修改一个数据库
SYNOPSIS ALTER DATABASE name SET parameter { TO | = } { value | DEFAULT } ALTER DATABASE name RESET ...
- 表单文件上传编码方式(enctype 属性)
enctype 属性规定在发送到服务器之前应该如何对表单数据进行编码. 如下: <form action="upload.php" method="post&quo ...
- windows sdk编程禁止改变窗体大小
#include <windows.h> /*消息处理函数声明*/ HRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM ...
- 用闭包方式实现点击a标签弹也索引值
var self = document.getElementsByTagName("a"); for(var i=0;i<self.length;i++){ self[i]. ...
- MFC如何设置窗口最前
首先,放到最前 this->SetWindowPos(&wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);//使窗口总是在最前面 this->Se ...
- java线程池,信号量使用demo
直接上代码 package org.jimmy.threadtest20181121; import java.util.concurrent.LinkedBlockingQueue; import ...
- java实现搜索文件夹中所有文件包含的关键字的文件路径(递归搜索)
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...