如何在Mac上为Ubuntu交叉编译Go程序? [英] How do I cross-compile a Go program on a Mac for Ubuntu?

查看:213
本文介绍了如何在Mac上为Ubuntu交叉编译Go程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

vagrant@precise64:/vagrant$ sudo ./myprogram 
./myprogram: 1: ./myprogram: Syntax error: "(" unexpected

当我没有从同一个操作系统生成二进制文件时,我发现了这种情况,我做了 go使用Mac OS创建,但我需要从使用Ubuntu Linux的Vagrant运行这个二进制文件。我应该使用什么命令而不是从Mac制作我可以在Vagrant环境中运行二进制程序?

I found out this happens when I do not generate the binary file from the same OS. I do go build with Mac OS but I need to run this binary from Vagrant that uses Ubuntu Linux. What command should I use instead of go build from Mac so that I can run the binary program in Vagrant environment?

推荐答案

您需要设置一个交叉编译环境(通过构建去编译器自己)Dave Cheney的博客有很好的说明: http://dave.cheney.net/2013/07/09/an-introduction-to-cross-compilation-with-go-1-1

You need to set up a cross-compilation environment (by building the go compiler yourself). Dave Cheney's blog has good instructions: http://dave.cheney.net/2013/07/09/an-introduction-to-cross-compilation-with-go-1-1

这篇关于如何在Mac上为Ubuntu交叉编译Go程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆