dqg17080 2015-09-14 04:45 采纳率: 0%
浏览 361
已采纳

如何将Go程序从Mac OS X交叉编译到Ubuntu 64位

As the title says I'm wondering how to cross-compile my program so that I can run it on Ubuntu 64-bit

I've went into the /usr/local/go/src folder and ran

GOOS=linux GOARCH=amd64 ./make.bash --no-clean

everything compiled fine

then went into my project directory and ran go build -v -a and then took the compiled binary and moved it to my linux server, but when running it I get this error:

root@PanicCSGO40:~/test# ./test
-bash: ./test: cannot execute binary file: Exec format error
root@PanicCSGO40:~/test# sudo ./test
./test: 1: ./test: Syntax error: "(" unexpected
root@PanicCSGO40:~/test#

Not sure what I am doing wrong any information would be great thanks.

I've also tried doing it with GOARCH=386 but still get the same errors. Thanks!

This link does not solve my question because the chosen answer is a link to a blog post which relies heavily on doing all cross-compilation on using the blog writers bash scripts to do it, I just simply wanted to know what the correct way to do it was and now I do.

  • 写回答

1条回答 默认 最新

  • douya7309 2015-09-14 05:02
    关注

    The build command needs to identify the target environment:

    $ GOOS=linux GOARCH=amd64 go build -v /path/to/target/package
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测