具有ARC支持的静态库链接到非ARC项目,从而导致链接器错误 [英] Static library with ARC support linked to non-ARC project causing linker errors

查看:69
本文介绍了具有ARC支持的静态库链接到非ARC项目,从而导致链接器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用支持ARC的静态库的非ARC项目.这是受支持的方案,因此一切正常.也就是说,直到我在包括模拟器在内的4.x设备上运行代码.在这种情况下,代码会崩溃并显示以下链接器错误:

dyld: lazy symbol binding failed: Symbol not found: _objc_storeStrong
  Referenced from: /Users/zoul/Library/Application Support/iPhone Simulator/4.3.2/Applications/…/Demo.app/Demo
  Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/Foundation.framework/Foundation

一旦某些启用ARC的代码尝试调用_objc_storeStrong函数(例如在init方法(self = [super init])中),就会发生这种情况.将主项目转换为ARC可解决此问题,但我想知道是否还有其他解决方案.

我假定工具链可能已添加了要链接的必要库,以使ARC正常工作.因此,链接记录可能包含此信息.如果应用程序本身的项目未启用ARC,则默认情况下您可能无法获得它们,但仍可以通过显式定义它们来链接到它们.

查看构建记录,您确实可以在其中找到合适的链接器标记:它称为-fobjc-arc(与相关的编译器标记一样).当您将此设置添加到其他链接器标志"时,链接器将在主要构建产品中包含ARC库,并且代码应运行正常.

I have a non-ARC project that uses an ARC-enabled static library. This is a supported scenario, so that everything works fine. That is, until I run the code on a 4.x device, including the Simulator. In that case the code blows up with the following linker error:

dyld: lazy symbol binding failed: Symbol not found: _objc_storeStrong
  Referenced from: /Users/zoul/Library/Application Support/iPhone Simulator/4.3.2/Applications/…/Demo.app/Demo
  Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/Foundation.framework/Foundation

This happens as soon as some of the ARC-enabled code attempts to call _objc_storeStrong function, like in an init method (self = [super init]). Converting the main project to ARC solves the problem, but I’d like to know if there are other solutions.

解决方案

I assumed that the toolchain may have added the necessary libraries to link to, in order for ARC to work properly. So the linker transcript may contain this piece of information. If the project of the app itself is not ARC-enabled, you may not get these by default, but you could still link to them by defining them explicitly.

Looking at the build transcript you can indeed find the appropriate linker flag there: it’s called -fobjc-arc (just as the related compiler flag). When you add this setting to Other Linker Flags, the linker will include the ARC library with the main build product and the code should run fine.

这篇关于具有ARC支持的静态库链接到非ARC项目,从而导致链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆