"Symbol not found" Crash while Testing Mac OS X 10.7-specific code on 10.6 - objective-c

I have an application that uses a few classes found only in 10.7 Lion. (For example, NSFileCoordinator.)
When my application launches, it can use NSFileCoordinator to coordinate read access to the data store. (I save to XML.)
The application launches fine under 10.7 Lion, but when launching under 10.6 Snow Leopard, the application crashes with the error shown below.
My base SDK is set to 10.7, and the deployment target is 10.6. As far as I can tell, all my code is properly wrapped, like:
if (NSClassFromString(#"NSFileCoordinator") != nil) {
// Do something the 10.7 way
} else {
// Do something the 10.6 way
}
But for some reason, I'm still seeing the crash. Since the Base SDK is 10.7, I can't run the application under Xcode in 10.6, making debugging difficult. Additional messages are being logged to the console:
9/1/11 9:48:03 AM [0x0-0x18018].com.me.myapp[173] dyld: Symbol not found: _OBJC_CLASS_$_NSFileCoordinator
9/1/11 9:48:03 AM [0x0-0x18018].com.me.myapp[173] Referenced from: /Volumes/Macintosh HD/Users/Me/Library/Developer/Xcode/DerivedData/Mac-ebdxgdvcqfnptlftkreamrwdxetd/Build/Products/Debug/myapp.app/Contents/MacOS/myapp
9/1/11 9:48:03 AM [0x0-0x18018].com.me.myapp[173] Expected in: /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
9/1/11 9:48:03 AM [0x0-0x18018].com.me.myapp[173] in /Volumes/Macintosh HD/Users/Me/Library/Developer/Xcode/DerivedData/Mac-ebdxgdvcqfnptlftkreamrwdxetd/Build/Products/Debug/myapp.app/Contents/MacOS/myapp
And the crash report:
Process: myapp [137]
Path: /Volumes/Macintosh HD/Users/Me/Library/Developer/Xcode/DerivedData/Mac-ebdxgdvcqfnptlftkreamrwdxetd/Build/Products/Debug/myapp.app/Contents/MacOS/myapp
Identifier: com.me.myapp
Version: 1.5.0 (150)
Code Type: X86-64 (Native)
Parent Process: launchd [92]
Date/Time: 2011-09-01 09:40:32.591 -0400
OS Version: Mac OS X 10.6.8 (10K549)
Report Version: 6
Interval Since Last Report: 2009 sec
Crashes Since Last Report: 5
Per-App Crashes Since Last Report: 5
Anonymous UUID: 32784C79-0821-471E-BCBF-BE5874774075
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Crashed Thread: 0
Dyld Error Message:
Symbol not found: _OBJC_CLASS_$_NSFileCoordinator
Referenced from: /Volumes/Macintosh HD/Users/Me/Library/Developer/Xcode/DerivedData/Mac-ebdxgdvcqfnptlftkreamrwdxetd/Build/Products/Debug/myapp.app/Contents/MacOS/myapp
Expected in: /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
in /Volumes/Macintosh HD/Users/Me/Library/Developer/Xcode/DerivedData/Mac-ebdxgdvcqfnptlftkreamrwdxetd/Build/Products/Debug/myapp.app/Contents/MacOS/myapp

#Anomie has the right answer but let me expand on it some more.
Here is the code of a command line tool that is similar to what you are doing:
int main (int argc, const char * argv[])
{
#autoreleasepool {
if (NSClassFromString(#"NSFileCoordinator")) {
NSLog(#"Version >= 10.7");
} else {
NSLog(#"Version < 10.7");
}
}
return 0;
}
The only framework that this program links to is Foundation. But in order to weakly link to this framework you must do the following:
Click on the project in the project browser
Go to "Build Phases"
Go to "Link Binary With Libraries" and remove "Foundation.framework"
Go to "Build Settings" and add the following "Other Linker Flags":
-weak_framework Foundation
Rebuild your project. I've tested on OS X 10.6 and 10.7 and neither crashed and both produced the expected output. Hope this helps.

You need to weakly link the framework, so these unresolved symbols won't be an error at load time.

Related

xcode 5 crashes while opening xib developed in xcode6

I want to test my app for ios6. So, i downloaded xcode 5. In xcode5 While opening xib, xcode crashes with following log. Kindly suggest a solution.
Process: Xcode [2807]
Path: /Applications/Xcode 2.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 5.0 (3332.25)
Build Info: IDEApplication-3332025000000000~2
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [2807]
User ID: 501
Date/Time: 2015-07-14 12:55:38.017 +0500
OS Version: Mac OS X 10.10.3 (14D131)
Report Version: 11
Anonymous UUID: F20A6FAB-50EF-797B-17ED-DCA402DAE3BA
Time Awake Since Boot: 11000 seconds
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Application Specific Information:
ProductBuildVersion: 5A1413
ASSERTION FAILURE in /SourceCache/IDEInterfaceBuilderCocoaTouch/IDEInterfaceBuilderCocoaTouch-3742/IBPlugin/Utilities/IBObjectMarshalling.m:36
Details: Failed to launch cocoa touch tool: Error Domain=com.apple.InterfaceBuilder Code=-1 "Interface Builder encountered an error communicating with the iOS Simulator." UserInfo=0x7fa34bda8380 {NSUnderlyingError=0x7fa34b78c2f0 "The operation couldn’t be completed. (IBMessageChannelErrorDomain error 1.)", NSLocalizedDescription=Interface Builder encountered an error communicating with the iOS Simulator., NSLocalizedRecoverySuggestion=Please check Console.app for crash reports for "Interface Builder Cocoa Touch Tool" for further information., NSLocalizedFailureReason="Interface Builder Cocoa Touch Tool" (2879) failed to launch and exited with status (null), signal 6.}
Object: <NSThread: 0x7fa341c2bb30>
Method: -cocoaTouchToolForTargetRuntime:
Thread: <NSThread: 0x7fa341c2bb30>{number = 1, name = main}
Hints: None
In the File Inspector of the XIB file, there's a "Interface Builder Document" popup and one of choices is "Opens in". And from there you can select "Xcode 5".
If you have auto-layout turned on, then the lowest you can go is Xcode 5.1.

XCode6 keeps crashing when I try to export ad-hoc build

[UPDATE]
Problem has been solved after going Apple dev site and accept new Term and Condition agreement, this is the most strange problem I ever seen.
I am able to build and run app without any problem until create ad-hoc build, Xcode6 (version 6.0.1) will always crash after choosing account and team and throw below exception:
Process: Xcode [1861]
Path: /Applications/Xcode.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 6.0.1 (6528)
Build Info: IDEFrameworks-6528000000000000~2
App Item ID: 497799835
App External ID: 712682811
Code Type: X86-64 (Native)
Parent Process: launchd [258]
Responsible: Xcode [1861]
User ID: 501
Date/Time: 2014-09-26 13:07:23.360 +0700
OS Version: Mac OS X 10.9.5 (13F34)
Report Version: 11
Anonymous UUID: E2DD7234-2A56-B169-B657-56CFED90D316
Crashed Thread: 10 Dispatch queue: com.apple.root.default-priority
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Application Specific Information:
ProductBuildVersion: 6A317
UNCAUGHT EXCEPTION (NSInvalidArgumentException): *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]
UserInfo: (null)
Hints: None
Is anyone experiencing this? please help.
Note: I already choose team in Target config.

How to remove last selected file in Xcode 5 project navigator

My Xcode 5 is crashing continuously for one project when i am changing project navigator selection from xib file to any other file. so how to reset Xcode 5 preferences in mavericks?
Process: Xcode [11348]
Path: /Applications/Xcode.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 5.0 (3332.22)
Build Info: IDEApplication-3332022000000000~2
Code Type: X86-64 (Native)
Parent Process: launchd [476]
Responsible: Xcode [11348]
User ID: 501
Date/Time: 2013-11-19 20:17:51.222 +0530
OS Version: Mac OS X 10.9 (13A603)
Report Version: 11
Anonymous UUID: 7CAA04DB-9AE5-4DB6-4EA0-12DF215191FF
Sleep/Wake UUID: BC5C337A-14F4-4375-8EF4-397D0F2DB159
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Application Specific Information:
ProductBuildVersion: 5A1412
ASSERTION FAILURE in /SourceCache/IDEInterfaceBuilder/IDEInterfaceBuilder-4510/CocoaIntegration/ResourceManagement/IBCocoaResourceManager.m:73
Details: result should be an instance inheriting from NSImage, but it is IBCIImage
Object: <IBCocoaResourceManager: 0x7f85f54072a0>
Method: -placeholderResourceContentForMediaType:originalValue:
Thread: <NSThread: 0x7f85f0c150e0>{name = (null), num = 1}
Hints: None
Go to your .xcodeproj in Finder, and right click, select show package contents. Then select the project.xcworkspace file within and show package contents on that as well, then open the xcuserdata folder, open the yourusername.xcuserdatad folder. You will see a UserInterfaceState.xcuserstate file. Delete it. Then open back up your .xcodeproj file.

Avoid adding NSWindowWillEnterFullScreenNotification in OS version prior Lion(On Leopard or Snow Leopard)

How can I avoid adding NSWindowWillEnterFullScreenNotification in OS version prior to 10.7 because it is only available in OS 10.7 or above and I want to use this notification in above 10.7 but my application got crashed if I run it on prior OS version.
I have check the crash log and it was saying that
Symbol not found NSWindowWillEnterFullScreenNotification
Right now I am checking the OS version using this
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_5) {
/* On a 10.5.x or earlier system */
}
else if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_6) {
/* On a 10.6 - 10.6.x system */
} else {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(willEnterFull:)
name:NSWindowWillEnterFullScreenNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(didExitFull:)
name:NSWindowDidExitFullScreenNotification
object:nil];
}
But app got crashed in prior version as soon as it get launched.
Here is the crash log although I have change the app name to XYZ in the log due to NDA
Process: XYZ [53319]
Path: /Applications/XYZ.app/Contents/MacOS/XYZ
Identifier: com.XYZ.XYZ
Version: 2.0.5 (2.0.5)
Code Type: X86 (Native)
Parent Process: launchd [224]
Date/Time: 2012-10-28 07:44:11.717 -0500
OS Version: Mac OS X 10.6.8 (10K549)
Report Version: 6
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Crashed Thread: 0
Dyld Error Message:
Symbol not found: _NSWindowDidExitFullScreenNotification
Referenced from: /Applications/XYZ.app/Contents/MacOS/XYZ
Expected in: /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
in /Applications/XYZ.app/Contents/MacOS/XYZ
Here's what I think happens. The crash happens already in the linker, because it expects NSWindowDidExitFullScreenNotification to exist, but it doesn't in older versions of os x.
I haven't got any experience in this. The solutions seem to be kind of hacky.
Have a look at this question, where someone has an almost exact same question:
How to build a backwards compatible OS X app, when a new API is present?

Static Library and -weak-lSystem

I build a static library that links against other frameworks, particularly CoreLocation. I want to use features provided by iOS 5 but be compatible with 4.3.
My app crash at launch when I start it on iOS devices in 4.3 with this error :
Date/Time: 2012-08-22 16:44:53.900 +0200
OS Version: iPhone OS 4.3.3 (8J3)
Report Version: 104
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x00000001, 0xe7ffdefe
Crashed Thread: 0
Dyld Error Message:
Symbol not found: _UIKeyboardDidChangeFrameNotification
The problem I encounter is described in this post : iOS 4 app crashes at startup on iOS 3.1.3: Symbol not found: __NSConcreteStackBlock.
But how do you deal with that when building a static library ?? I can't compile when I set the -weak-lSystem flag. Here is a trace :
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: -dynamic not specified, -all_load invalid
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: -dynamic not specified the following flags are invalid: -ObjC
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -weak-lSystem
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -weak-lSystem is not an object file (not allowed in a library)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib/libxml2.2.dylib is a dynamic library, not added to the static library
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib/libxml2.2.dylib is a dynamic library, not added to the static library
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib/libz.dylib is a dynamic library, not added to the static library
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib/libz.dylib is a dynamic library, not added to the static library
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool failed with exit code 1
Resolved
See accepted answer below and do not forget to mark libraries used in different versions as Optional in Xcode. Ex: I use UIKit new notification for iOS 5 but my deployement target is 4.3 so I need to mark this library as Optional in order to make things work. It is the same for CoreLocation CLGeocoder new iOS 5 class.
The problem is that UIKeyboardDidChangeFrameNotification is not available on iOS 4 and therefore the dynamic loader (Dyld) fails.
From the perspective of the static library developer you don't have to do anything. The -weak-lSystem flag should be set in the Xcode project that uses the static library for an application (see the post mentioned in the question) - not in the project for the static library.