Build error when compiling for iPhone (with solution!)
Status: Beta
Brought to you by:
jengelhart
When compiling a native iPhone app with RegexKitLite build fails because of the following error:
'NSScannedOption' undeclared (first use in this function)
This error only appears when building for an actual device. I had no problems building for the simulator. I was able to build successfully by adding the following to line 578 of RegexKitLite.m:
NSUInteger NSScannedOption = (1<<0);
(NSScannedOption is used undeclared on line 579 before this addition.)
I realize that this solution is just a stopgap and look forward to an official update that addresses the problem. Thanks for sharing your efforts with the rest of us John. A programming language without regular expressions is like a sandwich without bread.
I've 'fixed' this with the following modification to the source:
#ifdef __OBJC_GC__
else { if((splitStrings = rkl_realloc(&scratchBuffer[1], splitStringsSize, (NSUInteger)NSScannedOption)) == NULL) { goto exitNow; } }
#else
// http://sourceforge.net/tracker/index.php?func=detail&aid=2050825&group_id=204582&atid=990188
// This is to get around an iPhone quirk. For whatever reason, the iPhone NSZone.h explicitly removes all NSAllocateCollectable()
// bits and pieces using #if pre-processor conditions. Since NSScannedOption is only really used when the compiler has -fobjc-gc enabled,
// we just chop it out here.
else { if((splitStrings = rkl_realloc(&scratchBuffer[1], splitStringsSize, 0)) == NULL) { goto exitNow; } }
#endif
I don't actually have the iPhone tool chain installed, so I can't test it, but I'm fairly confident that this will 'fix' the problem. This fix assumes that __OBJC_GC__, which is defined by the compiler when -fobjc-gc is in effect, is not defined when building for the iPhone. This seems like a pretty safe assumption since the iPhone does not support any form of Cocoa GC memory management.
In reality, if __OBJC_GC__ isn't defined, RegexKitLite will never call NSAllocateCollectable() anyways. This means the third argument to rkl_realloc is never used when __OBJC_GC__ isn't defined. It (was) harmless because at least 10.4 included NSAllocateCollectioable() and NSScannedOption, even though 10.4 didn't support GC.