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

时间:2022-03-24 04:55:19

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.

我最近从XCode 3升级到4,现在我的iPhone项目出现了构建问题。我需要支持iOS的旧版本回到3.1。对于XCode 3.2.5,使用SDK 4.2构建没有问题,使用的iOS部署目标是3.1。我还包含到libSystem的弱链接。B库,用于在旧的iOS版本上运行应用程序。现在,当我用XCode 4构建时,我得到了下面的链接错误。编译步骤完成,但是链接步骤失败。如果我删除到libSystem的弱链接。B库,然后构建完成,但是在ios3.1上运行时,应用程序在启动时崩溃。

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

有人找到解决这个问题的办法了吗?如何使用XCode 4构建,在旧版本的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

ld:没有找到-lSystem的库。B collect2: ld返回1退出状态命令/开发者/平台/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2以退出代码1失败。

4 个解决方案

#1


6  

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

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

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

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

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

#2


4  

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

好的,weak_library选项是正确的路径…这是问题:

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

. b表示系统库的第二个版本。我猜想一些新的object - c特性需要这样(比如block),使用那些为块提供API支持的库,这些库将间接引用. b系统库。这意味着动态链接器将尝试引入libSystem。B,但间接地(如果您的代码没有使用这些特性)。

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.

要让它在旧手机上运行,您必须为libSystem.B指定一个弱链接。弱链接使它使得丢失比特的旧库不会引起问题。对于普通链接,动态链接器需要找到所有可能被使用的符号。对于弱链接,链接器允许丢失项目。这是苹果对老款手机的部分支持……如果它在库中丢失了一个符号,不要担心。

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.

不幸的是,5.1仿真器SDK不包含libSystem.B。dylib文件,这就是为什么上面的几个解决方案—工作…如果您将一个文件放入其中,它至少不会死于构建。

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.

不过,请确保您在创建这个文件时理解了正在做什么。你告诉链接器在模拟器上运行时要在那个库中链接……因此,它必须具有正确的arch,并且必须与框架中的其他库进行适当的交叉连接。

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.

使用/usr/lib/libSystem.B是个坏主意,因为它是一个OSX库,而不是iOS库。类似地,连接到设备库将获得一个带有arm arch的库,在运行在英特尔硬件上的sim卡中,这个库将不起作用。

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.

使用libSystem。B从一个年长的SDK是一个更好的主意,和可能会工作,但鉴于它看起来像苹果是不遵循自己的建议与库版本(5.1看起来与他们再次把版本),我猜,这也会造成问题。

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:

所以,如果你想支持旧的设备,你想让sim卡正常工作,最好的方法是:

  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. 添加libSystem.B。dylib与构建阶段中的库的链接是可选的(这等价于添加其他链接器标志-weak_library,但是找到了正确的文件)。
  3. Create a sym link from libSystem.dylib in the iOS SIMULATOR framework to libSystem.B.
  4. 从libSystem创建一个sym链接。在iOS模拟器框架中的dylib到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:

我的推理是,自从。b标志着版本控制的一个提升,从ios5开始。x将在stock库中具有所需的所有功能,因此可以假设. 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

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.

实际上,使用任何看起来有效的库都可能是安全的,因为在ios 5中实际运行时。x甚至目前并不寻找B版本....解决方案是通过旧设备的链接阶段……然而,似乎这个修复比上面列出的其他备选方案更安全。

Some Cross-References of Interest:

一些感兴趣的交叉引用:

Weak Linking in Frameworks

弱连接在框架

Developer Tools Weak Linking

开发工具弱连接

#3


3  

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

这是我的Xcode 4.0.2和SDK 4.3环境的解决方案,但我认为它也应该适用于其他设置。

  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. libSystem.B。dylib不在/Developer/ platform/ iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3中。sdk/usr/lib,但它适用于较低的sdk版本(如iPhoneOS4.2.sdk)
  3. most of the cases libSystem.B.dylib is just a symbolic link to libSystem.dylib
  4. 大多数情况下是libSystem.B。dylib只是libSystem.dylib的一个符号链接
  5. 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 :)
  6. 所以在iPhoneSimulator4.3。我已经应用了以下命令sudo ln -s libSystem。dylib libSystem.B。dylib和我的模拟器构建再次开始工作:)

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.

注意:libSystem.B。动态库是由Flurry和Urban Airship使用的,所以最好不要删除项目文件中的引用(当然,Urban Airship不能在模拟器下工作,但我认为Flurry可以。libSystem.B。dylib也可能是项目中包含的其他库所需要的。

#4


0  

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. 我复制libSystem.B。dylib文件来自我朋友的MAC (/Developer/ platform/ iPhoneOS.platform/Developer/SDKs/ iphoneos4.2 sdk/usr/lib/libSystem.B.dylib)。! ! !xCode 3.2.5在他的MAC上安装了4.0和4.2 sdk。! ! !
  3. Go to: ProjectSettings > Targets > BuildPhases > Link Binary With Libraries > '+'.
  4. 转到:ProjectSettings >目标为>构建阶段>链接二进制,使用库> '+'。
  5. 'Add other'. Select the copied libSystem.B.dylib file (you can locate it in your project bundle)
  6. “添加其他”。选择复制libSystem.B。dylib文件(您可以在项目包中找到它)
  7. Build...
  8. 构建……

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

在此之后,我没有得到“没有为-lSystem找到的库”。B”错误。

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

该应用还可以在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.

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

Good luck.

祝你好运。

#1


6  

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

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

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

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

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

#2


4  

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

好的,weak_library选项是正确的路径…这是问题:

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

. b表示系统库的第二个版本。我猜想一些新的object - c特性需要这样(比如block),使用那些为块提供API支持的库,这些库将间接引用. b系统库。这意味着动态链接器将尝试引入libSystem。B,但间接地(如果您的代码没有使用这些特性)。

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.

要让它在旧手机上运行,您必须为libSystem.B指定一个弱链接。弱链接使它使得丢失比特的旧库不会引起问题。对于普通链接,动态链接器需要找到所有可能被使用的符号。对于弱链接,链接器允许丢失项目。这是苹果对老款手机的部分支持……如果它在库中丢失了一个符号,不要担心。

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.

不幸的是,5.1仿真器SDK不包含libSystem.B。dylib文件,这就是为什么上面的几个解决方案—工作…如果您将一个文件放入其中,它至少不会死于构建。

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.

不过,请确保您在创建这个文件时理解了正在做什么。你告诉链接器在模拟器上运行时要在那个库中链接……因此,它必须具有正确的arch,并且必须与框架中的其他库进行适当的交叉连接。

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.

使用/usr/lib/libSystem.B是个坏主意,因为它是一个OSX库,而不是iOS库。类似地,连接到设备库将获得一个带有arm arch的库,在运行在英特尔硬件上的sim卡中,这个库将不起作用。

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.

使用libSystem。B从一个年长的SDK是一个更好的主意,和可能会工作,但鉴于它看起来像苹果是不遵循自己的建议与库版本(5.1看起来与他们再次把版本),我猜,这也会造成问题。

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:

所以,如果你想支持旧的设备,你想让sim卡正常工作,最好的方法是:

  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. 添加libSystem.B。dylib与构建阶段中的库的链接是可选的(这等价于添加其他链接器标志-weak_library,但是找到了正确的文件)。
  3. Create a sym link from libSystem.dylib in the iOS SIMULATOR framework to libSystem.B.
  4. 从libSystem创建一个sym链接。在iOS模拟器框架中的dylib到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:

我的推理是,自从。b标志着版本控制的一个提升,从ios5开始。x将在stock库中具有所需的所有功能,因此可以假设. 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

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.

实际上,使用任何看起来有效的库都可能是安全的,因为在ios 5中实际运行时。x甚至目前并不寻找B版本....解决方案是通过旧设备的链接阶段……然而,似乎这个修复比上面列出的其他备选方案更安全。

Some Cross-References of Interest:

一些感兴趣的交叉引用:

Weak Linking in Frameworks

弱连接在框架

Developer Tools Weak Linking

开发工具弱连接

#3


3  

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

这是我的Xcode 4.0.2和SDK 4.3环境的解决方案,但我认为它也应该适用于其他设置。

  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. libSystem.B。dylib不在/Developer/ platform/ iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3中。sdk/usr/lib,但它适用于较低的sdk版本(如iPhoneOS4.2.sdk)
  3. most of the cases libSystem.B.dylib is just a symbolic link to libSystem.dylib
  4. 大多数情况下是libSystem.B。dylib只是libSystem.dylib的一个符号链接
  5. 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 :)
  6. 所以在iPhoneSimulator4.3。我已经应用了以下命令sudo ln -s libSystem。dylib libSystem.B。dylib和我的模拟器构建再次开始工作:)

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.

注意:libSystem.B。动态库是由Flurry和Urban Airship使用的,所以最好不要删除项目文件中的引用(当然,Urban Airship不能在模拟器下工作,但我认为Flurry可以。libSystem.B。dylib也可能是项目中包含的其他库所需要的。

#4


0  

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. 我复制libSystem.B。dylib文件来自我朋友的MAC (/Developer/ platform/ iPhoneOS.platform/Developer/SDKs/ iphoneos4.2 sdk/usr/lib/libSystem.B.dylib)。! ! !xCode 3.2.5在他的MAC上安装了4.0和4.2 sdk。! ! !
  3. Go to: ProjectSettings > Targets > BuildPhases > Link Binary With Libraries > '+'.
  4. 转到:ProjectSettings >目标为>构建阶段>链接二进制,使用库> '+'。
  5. 'Add other'. Select the copied libSystem.B.dylib file (you can locate it in your project bundle)
  6. “添加其他”。选择复制libSystem.B。dylib文件(您可以在项目包中找到它)
  7. Build...
  8. 构建……

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

在此之后,我没有得到“没有为-lSystem找到的库”。B”错误。

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

该应用还可以在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.

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

Good luck.

祝你好运。