如何从 Mac OS X 交叉编译到 Linux x86?

发布于 2024-08-12 18:39:43 字数 164 浏览 9 评论 0原文

我正在运行 Mac OS X 10.5.8,并希望使用 GCC 4.1.2 为目标 CentOS 5.3 进行编译。我如何:

  1. 编译 GCC 4.1.2 工具链和相关工具?
  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:

  1. Compile GCC 4.1.2 toolchain and related tools?
  2. Use that tool to cross compile for target CentOS 5.3?

Any help is greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

岁月苍老的讽刺 2024-08-19 18:39:43

最简单的解决方案是在虚拟机中运行 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.

流年里的时光 2024-08-19 18:39:43

现在你可能可以使用 Docker for Mac 来做到这一点,我没有测试它,因为我没有麦克。 Docker 基本上创建了一个 Linux VM 并提供了一些不错的功能。

安装 docker 并准备构建映像。

  • 安装docker
  • 使用docker run -ti centos5.3 /bin/bash启动一个新容器(搜索官方 Docker Hub 为您想要的目标)
  • 安装您想要的 gcc 版本(类似于 sudo yum group install "Development Tools")
  • 退出容器
  • 运行 docker ps -a获取您的容器 ID
  • 将您的容器备份为基础构建镜像 docker commit [id] centos:build

进行构建

现在您可以使用您创建的构建环境进行 CentOS 构建。

  • 要启动构建环境,同时在其中安装工作目录,您可以使用类似 docker run -it --mount type=bind,source=$(pwd),target=/mnt centos:build /bin/sh - c "cd /mnt && bash"
  • 然后运行 ​​gcc ..../configuremake 或 < 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.

  • install docker
  • start a new container with docker run -ti centos5.3 /bin/bash (search the official Docker Hub for your desired target)
  • install your desired gcc version (something like sudo yum group install "Development Tools")
  • exit your container
  • run docker ps -a to obtain your container id
  • backup your container as base build image docker commit [id] centos:build

Make a build

Now you can use your created build environment for CentOS builds.

  • to start your build environment while mounting the working directory inside it you can use something like docker run -it --mount type=bind,source=$(pwd),target=/mnt centos:build /bin/sh -c "cd /mnt && bash"
  • then run gcc ... or ./configure or make or ninja or whatever to do your build
  • you can also run automated tests here if you wrote some

Docker 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).

残花月 2024-08-19 18:39:43

使用 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/

蘑菇王子 2024-08-19 18:39:43

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

云之铃。 2024-08-19 18:39:43

你可以使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文