GCC 4.2.1 在 Cygwin(Win7 64bit) for iPhone 上编译

发布于 2024-10-20 19:44:51 字数 1941 浏览 1 评论 0原文

这将需要很长时间来解释,但简短的版本是,我目前正在尝试为 ARMv7 编译 LLVM GCC 前端,以编译 Cortex-A8(iPhone 3GS) 的应用程序。我在编译 libgcc(gcc 编译过程的一部分)时遇到了 LD 的错误,这让我发疯!

命令是这样的:

/usr/llvm-gcc-4.2-2.8.source/build/./gcc/xgcc \
-B/usr/llvm-gcc-4.2_2.8.source/build/./gcc \
-B/usr/local/arm-apple-darwin/bin \
-B/usr/local/arm-apple-darwin/lib \
-isystem /usr/local/arm-apple-darwin/include \
-isystem /usr/local/arm-apple-darwin/sys-include \
-O2 -g -W -Wall -Wwrite-strings -wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -fno-inline -dynamiclib -nodefaultlibs -W1,-dead_strip \
-marm \
-install_name /usr/local/arm-apple-darwin/lib/libgcc_s.1.dylib \
-single_module -o ./libgcc_s.1.dylib.tmp \
-W1,-exported_symbols_list,libgcc/./libgcc.map
-compatibility_version 1 -current_version 1.0
-DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -Dinhibit_libc \
... long list of .o files ... \
-lc

结果通常是对 malloc、free、exit 等的大量未定义引用,这通常表明 libc 没有被编译。在查看 ld 抛出的错误列表后,我看到它试图拉入 /usr/lib/libc.a 并抱怨它不是正确的平台。好吧,这是有道理的,所以我花了 5 分钟在 google 上找到了答案。事实证明,如果我复制 libSystem.dylib 并将其重命名为 libc.dylib,应该可以解决问题,但事实并非如此。我在手机上找不到该文件的副本,因此我直接从 SDK 中提取它。然后我得到了这个奇怪的错误:

ld64: in /usr/local/arm-apple-darwin/lib/libc.dylib, can't re-map file, errno=22

此时,我做了我能想到的一切。我从 iPhone 中获取了 /usr/lib 文件夹的新副本,并确认 libSystem.dylib(和 libSystem.B.dylib)不在那里。我解压了 iOS 4.2.1 的原始 .ipsw 包,但我再次找不到 libSystem.dylib 的副本。我解压了 iPhoneSDK 和 MacOS SDK,并设法在两者中找到了它的副本,但该错误仍然存​​在。我复制了 libSystem.dylib、libSystem.B.dylib,尝试了重命名为 libc.dylib 的各种组合,但仍然除了错误之外什么也没有。我找不到一种方法让它识别该文件并链接到它。我还尝试链接 iphone SDK 中的 libc.a,但这也不起作用。我检查了 ./xgcc 正在发射什么,这是我新构建的 arm-apple-darwin-ld64 副本,应该没问题。

这里有一点背景知识。我构建了 LLVM+Clang 2.8,没有出现任何错误,并通过一些轻微的修改重新构建了 ODCCTools,以使其能够在 Cygwin 上进行编译(如果我能让它正常工作,我将在补丁中发布我的更改以及教程)。我还抓住了 iphone-dev“includes”和“csu”项目并成功完成了这些项目,尽管它们确实没有意义,因为我无法将其链接到 crt0.a。我的想法已经用完了。

谁能帮我解决这个问题吗?

This is going to take a long while to explain, but the short version is that I am currently attempting to compile the LLVM GCC frontend for ARMv7 to compile apps for the Cortex-A8(iPhone 3GS). I'm running into an error from LD when compiling libgcc(part of the gcc compilation process) that has been driving me mad!

The command is this:

/usr/llvm-gcc-4.2-2.8.source/build/./gcc/xgcc \
-B/usr/llvm-gcc-4.2_2.8.source/build/./gcc \
-B/usr/local/arm-apple-darwin/bin \
-B/usr/local/arm-apple-darwin/lib \
-isystem /usr/local/arm-apple-darwin/include \
-isystem /usr/local/arm-apple-darwin/sys-include \
-O2 -g -W -Wall -Wwrite-strings -wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -fno-inline -dynamiclib -nodefaultlibs -W1,-dead_strip \
-marm \
-install_name /usr/local/arm-apple-darwin/lib/libgcc_s.1.dylib \
-single_module -o ./libgcc_s.1.dylib.tmp \
-W1,-exported_symbols_list,libgcc/./libgcc.map
-compatibility_version 1 -current_version 1.0
-DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -Dinhibit_libc \
... long list of .o files ... \
-lc

And the result is typically a lot of undefined references to malloc, free, exit, etc. which typically indicate that libc is not getting compiled in. After going through the list of errors that ld is throwing, I see at the top that it is attempting to pull in /usr/lib/libc.a and complains that it is not the correct platform. Okay, that makes sense, so I spent 5 minutes on google and found an answer. Turns out that if I copy the libSystem.dylib and rename it to libc.dylib, that should solve the problem, but it doesn't. I couldn't find a copy of that file on my phone, so I pulled it directly from the SDK. I then get this strange error:

ld64: in /usr/local/arm-apple-darwin/lib/libc.dylib, can't re-map file, errno=22

At this point, I did everything I could think of. I grabbed a fresh copy of my /usr/lib folder from my iphone and confirmed that libSystem.dylib(and libSystem.B.dylib) wasn't there. I unpacked the raw .ipsw package for iOS 4.2.1 and once again, I could not find a copy of libSystem.dylib there either. I unpacked the iPhoneSDK and MacOS SDK and I managed to find a copy of it in both, but that error just kept persisting. I copied libSystem.dylib, libSystem.B.dylib, tried all sorts of combinations of renaming to libc.dylib and still nothing but errors. I can't find a way to get it to recognize the file and link against it. I also tried linking against the libc.a located in the iphone SDK and that didn't work either. I checked what ./xgcc was firing off, and it was my freshly built copy of arm-apple-darwin-ld64 which should be fine.

A little bit of background here. I built LLVM+Clang 2.8 with no errors, and I rebuilt the ODCCTools with some light modifications to get it to compile on Cygwin(I'll post my changes in a patch along with a tutorial if I can get this to work). I also grabbed the iphone-dev "includes" and "csu" project and those completed successfully, although there really is no point to them since I can't get it to link against crt0.a. I'm running out of ideas here.

Can anyone help me out on this?

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

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

发布评论

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

评论(1

雅心素梦 2024-10-27 19:44:51

我想我可能已经发现了错误。在 ODCCTools 深处,在第 2905 行的 ld.cpp 中,无法重新映射文​​件(因此出现了精彩的消息)。由于文件足够小,无需担心,因此我只是暂时删除了该重新映射并重新寻址了指针。我将花一点时间,为长期解决方案提出更好的修复方案(以及 ODCCTools 在 Cygwin 下工作的补丁)。

如果一切按计划进行,那么今晚晚些时候我将在 Cygwin 下为 iPhone 进行 GCC 编译器交叉编译。

I think I may have found out the error. Deep inside ODCCTools, inside ld.cpp on line 2905 it was failing to re-map the file(hence the wonderful message). Since the file was small enough to not worry about it, I just temporarily removed that remapping and just re-addressed the pointer. I'll spend a little time and come up with a better fix for long term solution(and a patch for ODCCTools to work under Cygwin).

If everything goes as planned, then I'll have the GCC compiler cross compiling for iPhone under Cygwin later tonight.

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