如何使用 libSystem.B 在 XCode 4 中构建 iOS 3.1 部署目标?

发布于 2024-10-23 19:29:39 字数 485 浏览 1 评论 0原文

我最近从 XCode 3 升级到 4,现在我的 iPhone 项目遇到了构建问题。我需要支持旧版本的 iOS 回 3.1。在 XCode 3.2.5 中,我使用 iOS 部署目标 3.1 来构建 SDK 4.2 没有任何问题。我还添加了一个到 libSystem.B 库的弱链接,这是在旧版 iOS 版本上运行应用程序所必需的。现在,当我使用 XCode 4 构建时,出现以下链接器错误。编译步骤完成,但链接步骤失败。如果我删除 libSystem.B 库的弱链接,则构建完成,但在 iOS 3.1 上运行时应用程序在启动时崩溃。

有没有人找到解决这个问题的方法?如何使用 XCode 4 进行构建以在旧版本的 iOS 上运行?

ld:找不到 -lSystem.B 的库 Collect2: ld 返回 1 退出状态 命令 /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 失败,退出代码 1

I've recently upgraded from XCode 3 to 4, and now I'm having build problems with my iPhone project. I need to support older versions of iOS back to 3.1. With XCode 3.2.5, I had no problem building with SDK 4.2, using an iOS deployment target of 3.1. I also included a weak link to the libSystem.B library, which is required for running the app on older iOS versions. Now when I build with XCode 4, I get the linker error below. The compilation step completes, but the link step fails. If I remove the weak link to the libSystem.B library, then the build completes, but the app crashes at startup when running on iOS 3.1.

Has anyone found a solution to this problem? How do you build with XCode 4, to run on an old version of iOS?

ld: library not found for -lSystem.B
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1

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

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

发布评论

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

评论(4

坠似风落 2024-10-30 19:29:39

在“其他链接器标志”下的项目构建设置中添加以下内容:

-weak_library /usr/lib/libSystem.B.dylib

它应该自动添加到您的目标构建设置中,但如果不是你也应该将它添加到那里。

In your project build settings under "Other Linker Flags" add the following:

-weak_library /usr/lib/libSystem.B.dylib

It should automatically be added to your Target build settings but if it isn't you should add it there as well.

独﹏钓一江月 2024-10-30 19:29:39

好的,weak_library 选项是正确的……问题如下:

.B 表示系统库的第二个版本。我猜测一些较新的 Obj-C 功能需要这个(如块),并且使用为块提供 API 支持的库,这样将间接引用 .B 系统库。这意味着动态链接器将尝试间接引入 libSystem.B(如果您的代码未使用这些功能)。

有两个相互竞争的问题:让应用程序在旧设备上运行,以及让它为模拟器构建。

为了让它在旧手机上运行,​​您必须为 libSystem.B 指定弱链接。弱链接基本上使得丢失位的旧库不会引起问题。通过正常链接,动态链接器需要找到所有可能使用的符号。由于链接较弱,链接器允许丢失项目。这是 Apple 对旧手机支持的一部分...如果库中缺少符号,请不要担心。

不幸的是,5.1 模拟器 SDK 不包含 libSystem.B.dylib 文件,这就是为什么上面的几个解决方案可以工作......如果你把一个文件放入其中可以找到,它至少不会死在建造。

不过,请确保您在创建此文件时了解自己在做什么。您告诉链接器在模拟器上运行时链接到该库......因此,它必须具有正确的架构,并且必须与框架中的其他库正确交叉链接。

使用 /usr/lib/libSystem.B 是一个坏主意,因为那是一个 OSX 库,而不是 iOS 库。同样,链接到 DEVICE 库将为您提供一个带有 arm arch 的库,该库无法在运行于英特尔硬件上的 sim 中运行。

使用旧版 SDK 中的 libSystem.B 是一个更好的主意,并且可能会起作用,但考虑到 Apple 似乎没有遵循自己的库版本控制建议(看起来 5.1 中他们再次放弃了该版本),我会我猜这也会引起问题。

因此,如果您想支持较旧的设备,并且希望 sim 正常工作,那么最好的方法似乎如下:

  1. 将 libSystem.B.dylib 添加到构建阶段中的与库的链接作为可选(这相当于添加其他链接器标志 -weak_library,但会为您找到正确的文件)。
  2. 创建从 iOS SIMULATOR 框架中的 libSystem.dylib 到 libSystem.B 的符号链接。

我的理由是,由于 .B 表明版本控制有所提高,并且 ios5.x 将在库存库中拥有所有所需的功能,因此可以假装 .B 版本与非版本控制库相同。对于 XCode 4.4(2012 年 7 月),这是通过以下方式完成的:

cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/usr/lib
sudo ln -s libSystem.dylib libSystem.B.dylib

实际上,使用任何看起来像有效库的东西可能都是安全的,因为当实际在 ios 5.x 中运行时,它当前甚至不查找 B 版本。 ..解决方法是绕过旧设备的链接阶段...尽管如此,此修复似乎比上面列出的其他替代方案更安全。

一些感兴趣的交叉引用:

弱链接框架

开发者工具弱链接

OK, the weak_library option is the right track...here are the issues:

The .B indicates a second version of the system library. I'm guessing some of the newer Obj-C features require this (like Blocks), and using libraries that give API support for blocks and such will indirectly reference the .B system library. This means the dynamic linker will try to pull in libSystem.B, but indirectly (if your code isn't using these features).

There are two competing problems: getting the app to work on older devices, and getting it to build for the simulator.

To get it to run on older phones, you'll have to specify a weak linkage for libSystem.B. Weak link basically makes it so older libraries that are missing bits don't cause problems. With normal linkage, the dynamic linker is required to find all of the symbols that could ever get used. With weak linkage, the linker allows for missing items. This is part of Apple's support for older phones...if it is missing a symbol in the library, don't worry about it.

Unfortunately, the 5.1 simulator SDK does NOT include a libSystem.B.dylib file, which is why several of the solutions above sort-of work...if you put a file in it can find, it at least won't die on build.

Make sure you understand what you are doing when you make this file, though. You are telling the linker to link in that library when running on the simulator...thus, it must have the correct arch, and must properly cross-link with other libraries in the frameworks.

Using /usr/lib/libSystem.B is a bad idea, as that is an OSX library, not an iOS one. Similarly, linking to a DEVICE library is going to get you a library with arm arch, which will not work in a sim running on intel hardware.

Using a libSystem.B from an older SDK is a better idea, and probably will work, but given that it looks like Apple is not following it's own advice with library versioning (it looks like with 5.1 they dropped the version again), I would guess that this is going to cause problems as well.

So, if you want to support older devices, and you want the sim to work properly, it seems like the best approach is as follows:

  1. Add libSystem.B.dylib to the Link With Libraries in Build Phases as OPTIONAL (this is equivalent to adding the other linker flag -weak_library, but finds the correct file for you).
  2. Create a sym link from libSystem.dylib in the iOS SIMULATOR framework to libSystem.B.

My reasoning is that since the .B indicates a bump in versioning, and since ios5.x will have all of the needed functionality in the stock library, it should be ok to pretend the .B version is identical to the non-versioned library. With XCode 4.4 (July 2012), this is done with:

cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/usr/lib
sudo ln -s libSystem.dylib libSystem.B.dylib

Really, it is probably safe to use anything that looks like a valid library simply because when actually running in ios 5.x it does not currently even look for the B version....the workaround is to get past the link phase for older devices...nevertheless, it seems like this fix is safer than the other alternatives listed above.

Some Cross-References of Interest:

Weak Linking in Frameworks

Developer Tools Weak Linking

居里长安 2024-10-30 19:29:39

这是我针对带有 SDK 4.3 环境的 Xcode 4.0.2 的解决方案,但我相信它也应该适用于其他设置。

  1. libSystem.B.dylib 不存在
    在下面
    /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/lib,
    但较低版本的 SDK 也有此功能
    版本(例如iPhoneOS4.2.sdk
  2. 大多数情况
    libSystem.B.dylib 只是一个
    libSystem.dylib 的符号
  3. 链接
    iPhoneSimulator4.3.sdk/usr/lib
    我已经应用了以下命令 sudo
    ln -s libSystem.dylib
    libSystem.B.dylib
    和我的模拟器
    构建再次开始工作:)

注意: libSystem.B.dylib 由 Flurry 和 Urban Airship 使用,因此您最好不要删除项目文件中的引用(当然Urban Airship 无法在 Simulator 下运行,但我认为您包含在项目中的其他库也可能需要 libSystem.B.dylib

Here's my solution for Xcode 4.0.2 with SDK 4.3 environment, but I believe it should also work on other setups.

  1. libSystem.B.dylib is not present
    under
    /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/lib,
    however it is present for lower SDK
    versions (e.g. iPhoneOS4.2.sdk)
  2. most of the cases
    libSystem.B.dylib is just a
    symbolic link to libSystem.dylib
  3. so in
    iPhoneSimulator4.3.sdk/usr/lib
    I've applied following command sudo
    ln -s libSystem.dylib
    libSystem.B.dylib
    and my simulator
    builds started to work again :)

NOTE: libSystem.B.dylib is used by Flurry and Urban Airship so you better don't delete the reference in project file (of course Urban Airship does not work under Simulator, but I think Flurry does. libSystem.B.dylib may also be required by other libraries you included to your project.

迷荒 2024-10-30 19:29:39

这是我的分步解决方案:

  1. 我从我朋友的 MAC 复制了 libSystem.B.dylib 文件 (/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/lib/libSystem. B.dylib)。 !!! xCode 3.2.5 通过 4.0 和 4.2 SDK 安装在他的 MAC 上。 !!!
  2. 转到:项目设置>目标>构建阶段>将二进制文件与库链接> '+'。
  3. “添加其他”。选择复制的 libSystem.B.dylib 文件(您可以在项目包中找到它)
  4. 构建...

此后我没有收到“找不到 -lSystem.B 的库”错误。

该应用程序还可以在 iOS < 设备上运行文件。 4.

这很奇怪,但问题似乎出在本机 libSystem.B.dylib 文件内。
Native - 我的意思是 xCode 的 4.0.2。

祝你好运。

Here is my step-by-step solution:

  1. I've copied libSystem.B.dylib file from my friend's MAC (/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/lib/libSystem.B.dylib). !!! xCode 3.2.5 was installed on his MAC with 4.0 and 4.2 SDKs. !!!
  2. Go to: ProjectSettings > Targets > BuildPhases > Link Binary With Libraries > '+'.
  3. 'Add other'. Select the copied libSystem.B.dylib file (you can locate it in your project bundle)
  4. Build...

After this I did not get 'library not found for -lSystem.B' error.

Also the app runs file on devices with iOS < 4.

It's very odd, but it seems that the problem is inside the native libSystem.B.dylib file.
Native - I mean xCode's 4.0.2.

Good luck.

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