douyu0845 2018-06-28 20:13
浏览 116
已采纳

无法从OSX交叉编译到Linux

When I try to cross compile my golang project from OSX to Linux, then I get following error message:

# runtime/cgo ld: unknown option: --build-id=none clang: error: linker command failed

and the compilation aborts.

This is how I try to build my application:

CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build

I also tried using gox:

 gox -os="linux"

but it still did not work.

Everything works as expected if I do not use the GOOS=linux tag and I am able to build/run my project for/on my OSX machine successfully.

  • 写回答

2条回答 默认 最新

  • dongwu8064 2018-07-04 06:49
    关注

    You need to install a proper toolchain to do that.

    In order to build binaries for architectures different that your build host, you need far more than just a cross-compiler - you need a full-blown toolchain, which can be a real pain to create, as you probably discovered.

    A couple of approaches:

    Use a proper Linux distribution in a virtual machine, such as VirtualBox. If you only want to build binaries for Linux/i386 on an MacOSX/x86_64 host, this is - in my opinion - the easiest, safest and most clean solution. It is not a cross-compiler, of course, but it works and it has the added advantage that you can actually test your executables.

    Use a script such crosstool-NG (a descendant of the original crosstool) to automatically build the toolchain - definitely easier than building it on your own, although you may have to compromise for slightly older compiler versions.

    Cross compiler for linux on mac os x

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 qt中connect两个signal
  • ¥20 pix2pixHD运行测试命令时出现数据类型错误无法反向传播的问题
  • ¥15 python处理Excel符合条件的行自动填写数据分类
  • ¥15 汇编hook举例并讲解(通俗易懂,学习用)
  • ¥20 用c++语言模拟键盘电子琴设计
  • ¥15 STM32cubemx生成keil工程,有问题与正常的情况不同,求解!
  • ¥15 如何自动点击银行app的安全键盘,实现密码自动输入
  • ¥15 关于四边形重叠的问题
  • ¥15 用verilog语言设计一个简易的八音符电子琴,可通过按键输入来控制音响。演奏时可以选择是手演奏(由键盘输入)或自动演奏已存入的乐曲。能够自动演奏多首乐曲,且每首乐曲可重复演奏
  • ¥15 sap gui脚本每次到导出Excel的时候就停住不动。不会另存为。