如何从 Mac OS X 交叉编译到 Linux x86?
我正在运行 Mac OS X 10.5.8,并希望使用 GCC 4.1.2 为目标 CentOS 5.3 进行编译。我如何:
- 编译 GCC 4.1.2 工具链和相关工具?
- 使用该工具交叉编译目标 CentOS 5.3?
非常感谢任何帮助!
I'm running Mac OS X 10.5.8 and want to compile for target CentOS 5.3 with GCC 4.1.2. How could I:
- Compile GCC 4.1.2 toolchain and related tools?
- Use that tool to cross compile for target CentOS 5.3?
Any help is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
最简单的解决方案是在虚拟机中运行 CentOS 5.3(例如 Sun VirtualBox)。这需要最少的设置,具有相当合理的开销(假设是 Intel Mac),并且您将能够实际测试和调试您正在构建的内容。
如果你真的坚持交叉编译,你必须构建一个交叉编译器。说明位于此处和此处,但请注意:您可能需要几天时间才能正确完成,然后您仍然需要虚拟机来测试结果,所以我认为这样做没有任何意义。
Your simplest solution is to just run CentOS 5.3 in a VM (e.g. Sun VirtualBox). This requires minimal setup, has quite reasonable overhead (assuming an Intel Mac), and you'll be able to actually test and debug what you are building.
If you really insist on cross-compiling, you must build a cross-compiler. Instructions are here and here, but beware: it will likely take you several days to get it right, and then you'll still need a VM to test the result, so I don't see any point in doing it that way.
现在你可能可以使用 Docker for Mac 来做到这一点,我没有测试它,因为我没有麦克。 Docker 基本上创建了一个 Linux VM 并提供了一些不错的功能。
安装 docker 并准备构建映像。
docker run -ti centos5.3 /bin/bash
启动一个新容器(搜索官方 Docker Hub 为您想要的目标)docker ps -a
获取您的容器 IDdocker commit [id] centos:build
进行构建
现在您可以使用您创建的构建环境进行 CentOS 构建。
gcc ...
或./configure
或make
或 < code>ninja 或其他任何东西来进行构建,如果您编写了一些Docker 与 VM,
。使用 docker,您可以使用您喜爱的终端以及您熟悉的主题和键盘映射。此外,它很可能会在启动和运行时消耗更少的资源。
如果您的应用程序是图形化的,并且您通过与其 GUI 交互来测试它,我想虚拟机仍然是更好的选择(请参阅@owned-Russian 的解决方案)。
Nowadays you can probably do it with Docker for Mac, I didn't test it because I have no mac. Docker basically creates a Linux VM and provides some nice-to-have functions.
Install docker and prepare your build image.
docker run -ti centos5.3 /bin/bash
(search the official Docker Hub for your desired target)sudo yum group install "Development Tools"
)docker ps -a
to obtain your container iddocker commit [id] centos:build
Make a build
Now you can use your created build environment for CentOS builds.
docker run -it --mount type=bind,source=$(pwd),target=/mnt centos:build /bin/sh -c "cd /mnt && bash"
gcc ...
or./configure
ormake
orninja
or whatever to do your buildDocker vs VM
With docker you can use your beloved terminal with your familiar theme and keymap. Furthermore it most probably will consume less resources for startup and while running.
If your app is graphical and you test it by using interaction with its GUI I guess a VM is still a better option (see @employed-russian's solution).
使用 Cocotron 直接从 Xcode 进行交叉编译。这里有一个很好的入门指南:http://blog.tlensing.org/tag/cocotron/< /a>
Use Cocotron to cross-compile directly from Xcode. There's a good getting-started guide here: http://blog.tlensing.org/tag/cocotron/
我努力让 crosstool-ng 在 OSX 10.9 上为 x86_64 Linux 构建。我在 如何构建 gcc 交叉编译器,由 Jeff Preshing 和他的脚本此处< /a> 作为对我有用的脚本的基础。在我的 OSX 版本上编译 glibc 时,链接中的脚本不起作用(对于从 OSX 到 Linux 的交叉编译来说,这似乎是一个非常常见的抱怨)。
我的脚本在这里: https://github.com/johnlondon/ OSX 上 linux 的交叉编译工具链
I struggled to get crosstool-ng to build on OSX 10.9 for x86_64 Linux. I used the very helpful post on how to build a gcc cross-compiler by Jeff Preshing and his script here as the basis for a script that worked for me. His script in the link doesn't work when compiling glibc on my version of OSX (which seems to be a very common complaint for those cross-compiling from OSX to Linux).
My script is here: https://github.com/johnlondon/Cross-compile-toolchain-for-linux-on-OSX
你可以使用crosstool-ng,或者如果你不想花太多时间来配置它,你可以下载一个预先配置的交叉编译器,如Linaro。
这是安装指南它在 Mac OS X 中。
You can use crosstool-ng, or if you don't want to spend too much time to configure it, you can download a pre-configured cross-compiler, as Linaro.
Here's the guide for installing it in Mac OS X.