各平台的GOOS和GOARCH参考

OS ARCH OS version

linux 386 / amd64 / arm >= Linux 2.6

darwin 386 / amd64 OS X (Snow Leopard + Lion)

freebsd 386 / amd64 >= FreeBSD 7

windows 386 / amd64 >= Windows 2000

$ cd /usr/local/go/src
$ sudo CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./make.bash

这里并不是重新编译Go,因为安装Go的时候,只是编译了本地系统需要的东西;而需要跨平台交叉编译,需要在Go中增加对其他平台的支持。所以,有 ./make.bash 这么一个过程。

执行结果类似如下:

sudo CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./make.bash
Password:

Building C bootstrap tool.

cmd/dist

Building compilers and Go bootstrap tool for host, darwin/amd64.

lib9
libbio
libmach
misc/pprof
cmd/addr2line
cmd/cov
cmd/nm
cmd/objdump
cmd/pack
cmd/prof
cmd/cc
……
pkg/text/template/parse
pkg/text/template
pkg/go/doc
pkg/go/build
cmd/go
pkg/runtime (linux/amd64)

Building packages and commands for host, darwin/amd64.

runtime
errors
sync/atomic
unicode
unicode/utf8
math
sync
unicode/utf16
crypto/subtle
io
syscall
……….
net/rpc/jsonrpc
testing/iotest
testing/quick

Building packages and commands for linux/amd64.

runtime
errors
sync/atomic
unicode
unicode/utf8
math
sync
unicode/utf16
……..
testing
net/rpc/jsonrpc
testing/iotest
testing/quick


Installed Go for linux/amd64 in /usr/local/go
Installed commands in /usr/local/go/bin

三、编译对应平台下的执行文件
到源代码目录下执行:

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build sina.go

不带前面参数的 go build 只是编译出开发环境适用的执行文件。

原文来自:http://m.oschina.net/blog/131480

Golang 交叉编译的更多相关文章

  1. 【GoLang】golang 交叉编译 实现&工具

    apt-get install gcc-mingw-w64 env CGO_ENABLED= GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc g ...

  2. [转载] Golang交叉编译(跨平台编译)简述

    一.何为交叉编译 简单地说,就是在一个平台上生成另一个平台上的可执行代码.同一个体系结构可以运行不同的操作系统:同样,同一个操作系统也可以在不同的体系结构上运行. 二.交叉编译前的准备 本文只介绍Wi ...

  3. 【备忘录】Golang交叉编译

    Golang 支持交叉编译,在一个windows平台可以生成linux或Mac系统下的可执行文件. Mac 下编译 Linux 和 Windows 64位可执行程序 CGO_ENABLED=0 GOO ...

  4. 【转】golang 交叉编译

    问题 golang如何在一个平台编译另外一个平台可以执行的文件.比如在mac上编译Windows和linux可以执行的文件.那么我们的问题就设定成:如何在mac上编译64位linux的可执行文件. 解 ...

  5. golang 交叉编译 win开发 linux生产

    windows平台之下使用 go env 能看到go本身的配置的环境变量,其中红框框起来的变量是交叉编译需要改动的选项, 由于是win平台开发,但是跑起来的程序都是在linux,所以linux转win ...

  6. Golang 交叉编译 window/linux 文件

    gox - 一款简单的交叉编译工具 下载地址:https://github.com/mitchellh/gox 使用 go get 命令安装: go get github.com/mitchellh/ ...

  7. Golang 交叉编译跨平台的可执行程序 (Mac、Linux、Windows )

    起因: 在项目中,我们每一次提交都需要添加commit 信息,而且我们的commit 信息,比较繁琐.我决定用golang语言编写一个小工具. 我决定使用语言:golang,使用工具:gox包. go ...

  8. golang交叉编译:Linux - Windows

    环境:Debian jessiego 1.7.4Windows 7 背景: 在debian中写好的程序编译后在windows上运行. 程序中使用了sqlite3 import( _ "git ...

  9. golang交叉编译笔记

    GOOS:目标平台的操作系统(darwin.freebsd.linux.windows) GOARCH:目标平台的体系架构(386.amd64.arm) Mac 下编译 Linux 和 Windows ...

随机推荐

  1. formvalidator4.1.3 使用过程中一些问题的解决

    在使用formvalidator4.1.3 插件时  发现 正常情况调用时没有问题的,但是我们的项目中需要把css  .js 之类的静态资源用单独的域名加载. 那么问题就来了在 该插件中 有一段这样的 ...

  2. eclipse快捷键失效的解决办法

    今天敲html代码,突然发现ctrl+D不能用了,shift+enter/shift+ctrl+enter也不能用了,上网上搜了下,原来我是在文本模式下打开的.切换为html editor打开就o了. ...

  3. js基础之动画(三)

    一.链式运动 首先,要改进运动框架 function getStyle(obj,attr){ if(obj.currentStyle){ return obj.currentStyle[attr]; ...

  4. mac 连接mysql提示 Warning: mysqli::real_connect(): (HY000/2002): No such file or directory

    mac 连接mysql的时候提示 Warning: mysqli::real_connect(): (HY000/2002): No such file or directory [说明1]MAC下M ...

  5. php base64_decode 解码方法

    <?php header('Content-Type:text/html;charset=utf-8'); function encode_file_contents($filename) { ...

  6. (DFS)zoj1008-Gnome Tetravex

    现在zoj暂时关了,实际上是在scuoj上做的. 题目地址 看起来题目比较复杂,实际上主要需要思维的是如何恰当的剪枝及合适的DFS角度. 问题等价于将n*n个可能相同的方块放到一个n*n的表中,使满足 ...

  7. [开发笔记]-DataGridView控件中自定义控件的使用

    最近工作之余在做一个百度歌曲搜索播放的小程序,需要显示歌曲列表的功能.在winform中采用DataGirdView来实现. 很久不写winform程序了,有些控件的用法也有些显得生疏了,特记录一下. ...

  8. CCNA 6.5

    no sh (no shutdown : start the interface)   router rspf 1 network x.x.x.x x.x.x.x area 0 int (interf ...

  9. Android中 服务里的方法抽取成接口

    1 写个类继承Service 重写 onBind方法 返回一个IBinder 对象(传递到连接成功时用) 2 服务中 写一个内部类 继承IBinder 并且实现一个接口(用于抽取方法)继承IBinde ...

  10. 数组的filter方法

    filter()函数用于过滤序列,filter()把传入的函数依次作用于每个元素,然后根据返回值是True还是False决定保留还是丢弃该元素. eg: var arr=[10,11,12,13,14 ...