1

UPDATE: please leave a comment when you have this working without problems on your system. That would confirm that this is a problem in my setup, rather than a bug in XCode.

After upgrading my development system to XCode 4.5.1, and compiling with IOS SDK 6.0, I get the following errors when running on the IOS 4.3 simulator:

dyld: lazy symbol binding failed: Symbol not found: _objc_release
  Referenced from: /Users/baraupp/Library/Application Support/iPhone Simulator/4.3.2/Applications/AFD73AB4-7047-468B-A20B-9C941850ED3C/Flyskyhy.app/Flyskyhy
  Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/Foundation.framework/Foundation

dyld: Symbol not found: _objc_release
  Referenced from: /Users/baraupp/Library/Application Support/iPhone Simulator/4.3.2/Applications/AFD73AB4-7047-468B-A20B-9C941850ED3C/Flyskyhy.app/Flyskyhy
  Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/Foundation.framework/Foundation

I have set the deployment target to 4.3, and I use ARC in the project, with some files on -fno-objc-arc. Compiling and linking succeeds without errors, it fails when trying to run on the simulator. It used to work fine before I upgraded.

EDIT:

I found a similar Stackoverflow question that asks almost exactly the same thing, and its answer suggests adding -fobjc-arc to the other linker flags. Unfortunately, that did not solve my problem. EDIT: I checked the flags that are actually used in the link phase, and the -fobjc-arc flag is present while linking, also without me adding -fobjc-arc explicitly.

As suggested by Brad in the comments, I added the library libarclite_iphoneos.a to the project, but that did not help either. I found that library in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc, which is a weird location in my view, but I could not find it anywhere else.

I also did 'nm' on that library, and it does not define the missing _objc_retain symbol either. It does define a _objc_retain$non_lazy_ptr, though, not sure what that means.

EDIT: I found out that the library gets ignored:

ld: warning: ignoring file libarclite_iphoneos.a, missing required architecture i386 in file libarclite_iphoneos.a

So obviously, it is not the correct file. But I cannot find the same file anywhere else on my system (I have searched with 'find').

Any ideas?

Community
  • 1
  • 1
fishinear
  • 6,101
  • 3
  • 36
  • 84
  • 1
    Unfortunately I cannot test that. I don't have a device on 4.3, and you cannot downgrade a device to a lower IOS version anymore nowadays. – fishinear Oct 15 '12 at 14:34
  • 1
    Have you tried adding `-fobjc-arc` to the Other Linker Flags for your application project? When targeting back to iOS 4.x, you might need to make sure that libarclite is built into your application. This normally is only needed when building a non-ARC application with an ARC library inside it, but maybe by turning off ARC on specific files you've triggered this. – Brad Larson Oct 15 '12 at 16:39
  • 1
    @BradLarson Yes, I have tried that, but that did not solve the problem. (it was what the answer to the mentioned question suggested; I should have stated that explicitly in my question). How can I "build libarclite into my application"? – fishinear Oct 15 '12 at 16:48
  • 1
    That linker flag should do it, but you could try the manual inclusion of that compatibility library that I had in the older version of this answer: http://stackoverflow.com/posts/8000517/revisions . Also, you really should test this on a device running 4.x, because the Simulator is not a good representation of how a device will behave running that OS. If you want to ship an application with support for an OS version, you need to have such a device or find someone with one of these devices willing to test this for you. I've caught a number of very subtle issues doing this. – Brad Larson Oct 15 '12 at 16:59
  • 1
    @BradLarson Thanks for your help, Brad. I added the library you suggest, but that did not help either. I have updated the question with what I have done, hope you can take a second look at it. And I have tested on a 4.3 device before and would love to do that again, but Apple makes that virtually impossible. I upgraded my old device by mistake and cannot downgrade it anymore. – fishinear Oct 15 '12 at 19:14
  • 1
    Sorry to ask this, but how do you manage to install 4.3 simulator on Xcode 4.5.1? Only 5.1 simulator appears to install on my machine – estemendoza Oct 19 '12 at 13:36
  • 1
    @estemendoza Both 6.0 and 4.3 simulators installed automatically with Xcode 4.5.1 in my case. But make sure you set your project and target deployment targets to 4.3, otherwise the 4.3 simulator will not show up in the list. To double-check which versions of the simulator are installed, check:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs – fishinear Oct 19 '12 at 15:14
  • 1
    @fishinear, thanks for that info, but the SDK for 4.3 is missing on the Xcode.app package and I installed version 4.5.1 today. Are you sure that 4.5.1 comes with 4.3 simulator? Regards – estemendoza Oct 20 '12 at 00:37
  • 1
    @estemendoza pretty sure, I definitely did not install it myself. It either was installed with 4.5.1 or it was automatically transfered from the earlier version of XCode. – fishinear Oct 21 '12 at 12:48
  • 1
    @fishinear, do you have Lion or Mountain Lion? If you have Lion, then yes, 4.5.1 should have install 4.3 simulator. The problem is that it is not installed on Mountain Lion :S – estemendoza Oct 22 '12 at 01:26
  • 1
    @estemendoza I indeed have Lion (10.7.5). – fishinear Oct 22 '12 at 10:51

1 Answers1

2

The problem was triggered by a +initialize method in a class category. Apparently, the Apple linker does not handle that case correctly.

After searching the web a lot, I saw that other people also have had issues with +load and +initialize methods, ARC and 4.3 compatibility.

In my case, I initialized a static variable in a category as such:

@implementation NSDictionary (FormAccess)

static NSRegularExpression *pattern;

+ (void) initialize
{
    pattern = [[NSRegularExpression alloc] initWithPattern:@"(\\w+)|\\[([0-9]+)\\]" options:0 error:nil];
}

...

@end

The problem disappeared when I replaced that with an explicit initialization the first time the variable was used. I did not need to add any linker flags.

Note that if you have a non-ARC project that uses some ARC files, you still need to add the "-fobjc-arc" flag to "Other Linker Flags", to avoid the same error message.

fishinear
  • 6,101
  • 3
  • 36
  • 84