24

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.

4
  • Are you linking using LLVM which supports ARC? Commented Jan 6, 2012 at 10:37
  • first though: the toolchain's probably just added a library to link when ARC is enabled by the main project. if you can't locate it in the transcripts, then you may be able to link to it by compiling one source with ARC. Commented Jan 6, 2012 at 10:41
  • 1
    That’s a great idea, @Justin! The trick with a single ARC-enabled file did not work, but I managed to find the right argument for the linker to include the library and it seems to work. Can you please that as an answer? A simple one will do, I’ll edit it to add the details. Commented Jan 6, 2012 at 10:48
  • @zoul great! answer added. edit away =) Commented Jan 6, 2012 at 11:23

2 Answers 2

30

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot, this answer was a life-saver after a whole afternoon trying to figure this out!
This no longer appears to work as of Xcode 4.3.2. -fobjc-arc seems to be an invalid flag for lib tool. ("unknown option character `f' in: -fobjc-arc")
I can confirm this is working in Xcode 4.3.2. I just did it, and the compiler didn't complain about anything when building for the simulator.
5

I'm adding a new answer to this as the previous accepted solution no longer appears to work with Xcode 4.3.2. I can only assume that the -fobjc-arc linker flag was never supposed to be exposed and has now been removed.

This appears to be a known issue although the only thread I can find on this with somebody from Apple commenting on the devforums dates back to mid-2011. From that thread, it is suggested that manually linking the following file solves the issue:

${DEVROOT}/Platforms/iPhoneOS.platform/Developer/usr/lib/arc/libarclite_iphoneos.a

This requires you to be compiling using the latest compiler/SDK though. I'm submitting this answer without testing, please upvote if it works, downvote if it doesn't!

3 Comments

Upvoting, since this is a useful addition. Did not test yet.
DEVROOT doesn't appear to work for me. I used: $(PLATFORM_DEVELOPER_USR_DIR)/lib/arc in the library search paths and a device-specific linker flag for -larclite_iphoneos
Useful addition, but I have yet to find the reason why just adding -fobjc-arc in the linker flags still works for me in Xcode 4.3.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.