iOS 4真的支持ARC吗?iOS 4.2 SDK在链接时缺少与arc相关的符号

时间:2022-09-07 07:37:43

I've read and heard since ARC was first announced that it was a compile-time thing and would be backwards-compatible with iOS 4. I have successfully refactored my project to ARC using Xcode 4.2's automatic refactoring, and when compiled against the iOS 5.0 SDK, it works fine. However, if I try to compile against my iOS 4.2 SDK, it fails at link time, missing the following symbols:

自从ARC第一次宣布它是一个编译时的东西并将与iOS 4向后兼容以来,我就一直在阅读和听到它。我已经成功地使用Xcode 4.2的自动重构将我的项目重构为ARC,并且当根据iOS 5.0 SDK编译时,它工作得很好。但是,如果我尝试用ios4.2 SDK进行编译,在链接时失败,缺少以下符号:

  • _objc_retainAutoreleaseReturnValue
  • _objc_retainAutoreleaseReturnValue
  • _objc_autoreleaseReturnValue
  • _objc_autoreleaseReturnValue
  • _objc_storeStrong
  • _objc_storeStrong
  • _objc_retain
  • _objc_retain
  • _objc_release
  • _objc_release
  • _objc_retainAutoreleasedReturnValue
  • _objc_retainAutoreleasedReturnValue

I checked, and these symbols are present in 5.0 but not 4.2:

我查了一下,这些符号出现在5.0中,而不是4.2中:

iPhoneOS5.0.sdk/usr/lib $ find . -type f|xargs nm|grep -i _objc_retain$
00005ed0 T _objc_retain
000061d0 T _objc_retain

iPhoneOS4.2.sdk/usr/lib $ find . -type f|xargs nm|grep -i _objc_retain$
[... *crickets* ...]

Does this mean that Apple lied? I assume instead that I'm confused and doing something wrong, but I can't figure out what.

这是否意味着苹果撒了谎?我认为我很困惑,做错了什么,但我不知道是什么。

This is with the GM release of Xcode 4.2 (Build 4C199)

这是Xcode 4.2的通用版本(构建4C199)

2 个解决方案

#1


34  

ARC is supported on iOS 4.3 and above. You need to use the iOS 5.x SDK but can select iOS 4.3 for the Deployment Target. The one thing that is not supported in 4.x is automatic weak reference zeroing.

iOS 4.3及以上版本支持ARC。你需要使用iOS 5。但是可以选择iOS 4.3作为部署目标。4中不支持的一项。x是自动弱参归零。

See Apple's documentation here for the Objective-C Feature Availability Index.

有关Objective-C特性可用性指数,请参阅苹果的文档。

Xcode 4.4 and 4.5 can be used to submit apps.

Xcode 4.4和4.5可用于提交应用程序。

Note that NSDictionary and NSArray subscripting deploys back to OS X 10.6 and iOS 4, be sure to set the deployment target back as well.

注意,NSDictionary和NSArray subscript将部署回OS X 10.6和ios4,请确保也将部署目标设置回。

#2


11  

A little bit late, but this is important information. The accepted answer is correct, Apple states iOS 4.0 and above as the minimum OS for ARC support.

有点晚了,但这是重要的信息。公认的答案是正确的,苹果将iOS 4.0及以上版本作为ARC支持的最低操作系统。

However, it can break in a few situations. One of them is of course the __weak keyword and it's derivatives. You will see an error like the following.

然而,它在一些情况下会崩溃。其中之一当然是__weak关键字,它是导数。您将看到如下所示的错误。

dyld: lazy symbol binding failed: Symbol not found: _objc_initWeak

A second and very dangerous condition is when you use the +load method of NSObject. If you do this using ARC on iOS 4.x you will have runtime crashes that are very hard to find. If you get runtime errors like the following, check your +load methods. For me it worked to set the -fno-objc-arc flag for that particular file.

第二个也是非常危险的情况是使用NSObject的+load方法。如果你在ios4上用ARC做这个。你会有运行时崩溃,这是很难找到的。如果出现如下所示的运行时错误,请检查+load方法。对我来说,它为那个特定的文件设置了-fno-objc-arc标志。

dyld: lazy symbol binding failed: Symbol not found: _objc_retainAutoreleasedReturnValue

#1


34  

ARC is supported on iOS 4.3 and above. You need to use the iOS 5.x SDK but can select iOS 4.3 for the Deployment Target. The one thing that is not supported in 4.x is automatic weak reference zeroing.

iOS 4.3及以上版本支持ARC。你需要使用iOS 5。但是可以选择iOS 4.3作为部署目标。4中不支持的一项。x是自动弱参归零。

See Apple's documentation here for the Objective-C Feature Availability Index.

有关Objective-C特性可用性指数,请参阅苹果的文档。

Xcode 4.4 and 4.5 can be used to submit apps.

Xcode 4.4和4.5可用于提交应用程序。

Note that NSDictionary and NSArray subscripting deploys back to OS X 10.6 and iOS 4, be sure to set the deployment target back as well.

注意,NSDictionary和NSArray subscript将部署回OS X 10.6和ios4,请确保也将部署目标设置回。

#2


11  

A little bit late, but this is important information. The accepted answer is correct, Apple states iOS 4.0 and above as the minimum OS for ARC support.

有点晚了,但这是重要的信息。公认的答案是正确的,苹果将iOS 4.0及以上版本作为ARC支持的最低操作系统。

However, it can break in a few situations. One of them is of course the __weak keyword and it's derivatives. You will see an error like the following.

然而,它在一些情况下会崩溃。其中之一当然是__weak关键字,它是导数。您将看到如下所示的错误。

dyld: lazy symbol binding failed: Symbol not found: _objc_initWeak

A second and very dangerous condition is when you use the +load method of NSObject. If you do this using ARC on iOS 4.x you will have runtime crashes that are very hard to find. If you get runtime errors like the following, check your +load methods. For me it worked to set the -fno-objc-arc flag for that particular file.

第二个也是非常危险的情况是使用NSObject的+load方法。如果你在ios4上用ARC做这个。你会有运行时崩溃,这是很难找到的。如果出现如下所示的运行时错误,请检查+load方法。对我来说,它为那个特定的文件设置了-fno-objc-arc标志。

dyld: lazy symbol binding failed: Symbol not found: _objc_retainAutoreleasedReturnValue