在 Mac 上交叉编译 iPhone?

发布于 2024-12-01 23:24:47 字数 132 浏览 0 评论 0原文

我该如何设置所有内容,以便从我的 OSX 10.7 Macbook pro 到我越狱的第 4 代 iPod touch 进​​行交叉编译。我的主要目标是能够将开源库移植到 iPhone 上。我似乎找不到任何关于 iOS 4 交叉编译的好/最近的文章。

How would I go about setting everything up to cross compile from my OSX 10.7 Macbook pro to my jailbroken 4th generation iPod touch. I'm mainly aiming to be able to port open source libraries to iphone. I can't seem to find any good/recent articles on cross compiling for iOS 4.

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

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

发布评论

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

评论(2

佞臣 2024-12-08 23:24:47

经过一番尝试,我发现可以使用 ./configure 并强制它为arm-apple-darwin11构建。您必须在 ./configure --some-flags 之后直接使用这些标志:

CPP="cpp" CXXCPP="cpp" 
CXX="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-g++-4.2" CXXFLAGS="-O -arch armv6 -arch armv7 -isysroot $SDK_ROOT/SDKs/iPhoneOS5.0.sdk" 
CC="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2" CFLAGS="-O -arch armv6 -arch armv7 -isysroot $SDK_ROOT/SDKs/iPhoneOS5.0.sdk" 
AR="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar" 
AS="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/as" 
LD="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ld"
LDFLAGS="-lstdc++ -arch armv6 -arch armv7 -isysroot $SDK_ROOT/SDKs/iPhoneOS5.0.sdk"
LIBTOOL="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool"
STRIP="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/strip" 
RANLIB="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ranlib"

CPP 和 CXXCPP 是所需的预处理器(默认); CC 和 CXX 是 Xcode 附带的用于 arm 的 c 和 c++ 编译器的路径,其他是编译器获取的标志或定义编译时使用的最常用工具的路径的宏。我不能保证一切都会奏效,但这是你应该做的一个好主意。
我建议向 ./configure 添加这些标志:

--prefix=/tmp/build --host=arm-apple-darwin11

它们的作用是帮助创建一个 makefile,该文件将在 /tmp/build 下的文件夹中发送库和程序。

After some attempt, I found out that it's possible to use ./configure and force it to build for arm-apple-darwin11. You have to use these flags directly after the ./configure --some-flags:

CPP="cpp" CXXCPP="cpp" 
CXX="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-g++-4.2" CXXFLAGS="-O -arch armv6 -arch armv7 -isysroot $SDK_ROOT/SDKs/iPhoneOS5.0.sdk" 
CC="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2" CFLAGS="-O -arch armv6 -arch armv7 -isysroot $SDK_ROOT/SDKs/iPhoneOS5.0.sdk" 
AR="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar" 
AS="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/as" 
LD="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ld"
LDFLAGS="-lstdc++ -arch armv6 -arch armv7 -isysroot $SDK_ROOT/SDKs/iPhoneOS5.0.sdk"
LIBTOOL="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool"
STRIP="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/strip" 
RANLIB="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ranlib"

CPP and CXXCPP are the preprocessor required (the default one); CC and CXX are the path to the c and c++ compiler for arm that comes with Xcode, the other are flags the compiler gets or macros that defines the path to the most common tools used when compiling. I cannot grant everything will work, but this is a good idea of what you should do.
I'd suggest to add to ./configure these flags:

--prefix=/tmp/build --host=arm-apple-darwin11

what they do is to help create a makefile that will send libs and programs in a folder under /tmp/build.

流云如水 2024-12-08 23:24:47

我也没有。我尝试的所有工具链最终都无法工作或创建 x86_64 二进制文件,这在 iOS 上无法工作。
我目前正在尝试直接在我的 iPad 上构建 apr,因为我已经从 Cydia 安装了所有必需的东西,但我陷入了 kqueue.c 无法正确编译的困境。我已经移植了lua和其他一些软件,所以我可以说它通常是这样工作的。在本机平台上构建而不是交叉编译的主要原因是某些程序依赖于其他程序(例如:apr 上的 apr-util),因此其中一些程序必须运行。但是,不可能在 intel 上运行 arm(至少没有仿真,并且 iPhone Simulator 使用 i386 二进制文件)。

任何对在 iOS 上使用/构建 UNIX 工具感兴趣的人都必须记住以下几点:

  • 您可能会找到您想要的东西,但并没有说它会按预期工作(这是专门针对开发人员的。示例:apr 是在Cydia,但它不是一个完整的包,所以构建apr-util是没有用的)。
  • 您必须使用越狱设备。如果您破坏了操作系统并需要恢复,这可能会成为一个问题。请务必保存 SHSH,以便您能够恢复到可越狱的 iOS。
  • 如果你找不到你要搜索的东西,事情就会变得非常混乱。大多数软件虽然被认为可以在通用 UNIX 系统上运行,但在 iOS 上可能会出现问题,iOS 在结构和工作方式上与 OS X 接近,但存在差异,特别是在与网络相关的部分下。
    另外,您可能必须对您构建的任何软件进行(伪造)代码签名。
  • 即使没有构建问题的软件也可能会带来不必要的意外:我已经成功为 iOS 构建了 apache2,但是当我运行时,我陷入了 SIGSYS,没有更多解释。

所以,要小心并做好准备,因为事情通常并不容易。

关于 Mac 没有工具链(Apple 提供的工具链除外)的事实,这可能可以解释,因为您不需要 Mac 来下载 Xcode,而 Mac 的成本通常高于开发人员愿意花的钱。这意味着尽管 Mac 硬件最近蓬勃发展,但没有多少人在做与您相同的事情。已经或多或少成功地为基于 Linux 的操作系统(例如 Ubuntu)构建了工具链。您始终可以尝试使用虚拟机。

Neither did I. All the toolchain I tried ended up in not working or creating x86_64 binaries, which won't work on iOS.
I'm currently trying to build apr directly on my iPad as I have installed from Cydia all the required things, yet I'm stuck kqueue.c not compiling properly. I have already ported lua and some other software, so I can say it generally works this way. The main reason for building on a native platform rather than cross compiling is that some programs rely on other programs (example: apr-util on apr) so some of them must be run. However, it's not possible to run arm on intel (at least without emulation, and iPhone Simulator uses i386 binaries).

Anyone who's interested in using/building UNIX tools on iOS has to keep these points in mind:

  • You might find what you wanted, but it's not said it'll work as expected (this is intended especially for developers. Example: apr is shipped in Cydia, but it's not a complete package, so it's useless to build apr-util).
  • You have to use a jailbroken device. This may become a problem if you break the OS and need to restore. Be always sure to save SHSH so that you're able to restore to a jailbreakable iOS.
  • If you don't find what you were searching, things will get pretty messy. Most software, although thought to work on generic UNIX system, might have problems on iOS, which is near OS X in structure and way to work, but has differences especially under the net-related sections.
    Plus you'll probably have to (fake)code sign any software you build.
  • Even software without build problems may hold unwanted surprises: I had successfully build apache2 for iOS, but when I run I got stuck with SIGSYS, without much more explanation.

So, beware and brace yourself, because things are not easy usually.

About the fact of Mac being without a toolchain (except the one provided by Apple), this may hold an explanation as you don't need to have a mac to download Xcode, while a mac cost usually more than devs are willing to spend. This means there aren't much people doing the same thing you do, despite the boom mac hardware has had recently. Toolchains have been more or less successfully built for Linux based OSes, such as Ubuntu. You can always try to use a VM.

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