Mac OS X 上的 Linux 交叉编译器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5245444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cross-compiler for Linux on Mac OS X?
提问by Daniel
I've been reading lots of documents on the internet about creating a cross compiler for linux on mac os x but can't seam to get any to work.
我一直在互联网上阅读大量有关在 mac os x 上为 linux 创建交叉编译器的文档,但无法缝合以使其正常工作。
It seams as if no one can help me with the question: Getting GMP to work with GCC 4.5.2
似乎没有人可以帮助我解决这个问题:让 GMP 与 GCC 4.5.2 一起工作
Is there any easy'er way to create a cross compiler?
有没有更简单的方法来创建交叉编译器?
采纳答案by thkala
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 originalcrosstool
) to automatically build the toolchain - definitely easier than building it on your own, although you may have to compromise for slightly older compiler versions.
在虚拟机中使用合适的 Linux 发行版,例如 VirtualBox。如果您只想在 MacOSX/x86_64 主机上为 Linux/i386 构建二进制文件,在我看来,这是最简单、最安全和最干净的解决方案。当然,它不是交叉编译器,但它可以工作,并且具有额外的优势,您可以实际测试可执行文件。
使用这样的脚本
crosstool-NG
(原始 的后代crosstool
)来自动构建工具链 - 绝对比自己构建更容易,尽管您可能不得不为稍旧的编译器版本妥协。
回答by jolyon
You need to:
你需要:
- install the xcode base build tools
- install the optional xcode command line tools
- install homebrew
- install the homebrew build tools
4.1 brew install crosstool-ng mpfr gmp grep
4.2 brew tap homebrew/dupes - create a case sensitive volume using "disk utility"
- use this volume to build the tool chain itself
6.1 generate a base configuration (for me this is an arm cortex a8)
6.1.1 ct-ng arm-cortex_a8-linux-gnueabi
6.2 use menuconfig (ct-ng menuconfig) to tweak the configuration
6.2.1. disable fortran and java (c compiler)
6.2.2. turn off static linking (c compiler)
6.2.3. change the paths to be on the volume you created above (paths and misc options)
6.2.4. remove dmalloc (debug facilities)
6.3 invoke the build:
6.3.1 ulimit -n 1024
6.3.2 ct-ng build
- 安装 xcode 基础构建工具
- 安装可选的 xcode 命令行工具
- 安装自制软件
- 安装自制构建工具
4.1 brew install crosstool-ng mpfr gmp grep
4.2 brew tap homebrew/dupes - 使用“磁盘实用程序”创建区分大小写的卷
- 使用此卷构建工具链本身
6.1 生成基本配置(对我来说这是一个 arm cortex a8)
6.1.1 ct-ng arm-cortex_a8-linux-gnueabi
6.2 使用 menuconfig ( ct-ng menuconfig) 来调整配置
6.2.1. 禁用 fortran 和 java(c 编译器)
6.2.2。关闭静态链接(c 编译器)
6.2.3。将路径更改为您在上面创建的卷(路径和其他选项)
6.2.4。删除 dmalloc(调试工具)
6.3 调用构建:
6.3.1 ulimit -n 1024
6.3.2 ct-ng build
with much thanks to the crosstools-nglist.
非常感谢crosstools-ng列表。