10

When I try to run my application in the iOS 4.3 simulator (Xcode 4.2), I crash when I hit @autoreleasepool{}, with:

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

I looked around, and I see the workaround is to add libarclite_iphoneos.a. There's a version of this for the simulator, too, as libarclite_iphonesimulator.a.

I need to add both libraries to my project to make it run on both the simulator and hardware. But whichever I build, it complains that the other library is for an unsupported architecture.

For example, building for simulator:

ld: warning: ignoring file /Developer-4.2/Platforms/iPhoneOS.platform/
Developer/usr/lib/arc/libarclite_iphoneos.a, missing required architecture
i386 in file

How do I fix both of these simultaneously? Or should I just stick with the old NSAutoreleasePool syntax for now?

Steven Fisher
  • 44,462
  • 20
  • 138
  • 192

3 Answers3

10

After a trials like clean, clean folder, resetting iPhone Simulator and even a restart, I changed the IPHONE_DEPLYMENT_TARGET on the target build setting down from iOS 5.0 to iOS 4.2. Worked.

amosel
  • 661
  • 8
  • 10
  • I will re-test, perhaps it's been fixed. Thanks. – Steven Fisher Dec 26 '11 at 04:06
  • @JohannesRudolph I use 4.2 Build 4D199 – amosel Dec 31 '11 at 04:57
  • This also worked for me when I suddenly started to see these errors after switching my deployment target to 4.2.1... – Kendall Helmstetter Gelner Feb 17 '12 at 18:06
  • Here is one further case where this can happen. I had specified a custom value (4.2.5) in IPHONEOS_DEPLOYMENT_TARGET in the project settings and not one of the caned values. This seems to have confused the linker into not linking the libarclite library. Changing this to a canned value of 4.3 seems to have fixed the problem. – Jon Steinmetz Apr 10 '12 at 02:15
1

You can use the Other Linker Flags build setting to link in the library, and specialize the value based on whether it's "Any iOS" or "Any iOS Simulator".

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • 1
    @StevenFisher: I'm rather mystified as to why this is necessary in the first place. Clang should be linking in the appropriate library for you when your deployment target is set pre-5.0. – Lily Ballard Oct 17 '11 at 20:00
  • Good point. I did some further testing. It looks like it's a problem when compiling for the simulator only. When compiling for the device, it automatically includes the device. I had to add `${PLATFORM_DEVELOPER_USR_DIR}/lib/arc` to `LIBRARY_SEARCH_PATHS` and `-larclite_iphonesimulator` to `OTHER_LDFLAGS[sdk=iphonesimulator*][arch=*]`, but there was no need to do a setting for the iOS hardware. So this is almost certainly a bug. – Steven Fisher Oct 17 '11 at 20:23
  • I haven't found a way to add this build setting 'OTHER_LDFLAGS[sdk=iphonesimulator*][arch=*]', could anyone tell me how to do that? – Thiago Peres Dec 25 '11 at 06:15
0

You can also merge the two static libraries to one universal library. Go to the Terminal and say

lipo -create -output /where/you/want/it/libarclite_universal.a /Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/arc/libarclite_iphoneos.a /Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/arc/libarclite_iphonesimulator.a

You can verify the resulting file by saying (in Terminal)

file /where/you/put/it/libarclite_universal.a

It should output:

libarclite_universal.a: Mach-O universal binary with 3 architectures
libarclite_universal.a (for architecture i386):current ar archive random library
libarclite_universal.a (for architecture armv6):current ar archive random library
libarclite_universal.a (for architecture armv7):current ar archive random library

Since this lib is linked statically, your final app wont grow because of the included sim library since only whatever is needed by your app will get linked into your final app.

Maciej Swic
  • 11,139
  • 8
  • 52
  • 68