Yesterday, as I was working on an AppShaker update, I came across a really tricky problem, that I think quite a few of you might experience so I'm detailing it here.
What happened is that I updated to the latest version of ASIHttpRequest, and also to the latest version of XCode 3.2 for iPhone OS 3.1 and again my project stopped compiling. More precisely it was the following code from ASIHttpRequest.m that was generating an error :
// Obtain the list of proxies by running the autoconfiguration script
#if !TARGET_OS_IPHONE || __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_2_2
CFErrorRef err2 = NULL;
NSArray *proxies = [(NSArray *)CFNetworkCopyProxiesForAutoConfigurationScript((CFStringRef)script,(CFURLRef)theURL, &err2) autorelease];
if (err2) {
return nil;
}
#else
NSArray *proxies = [(NSArray *)CFNetworkCopyProxiesForAutoConfigurationScript((CFStringRef)script,(CFURLRef)theURL) autorelease];
#endif
Basically it was always compiling the "else" clause, despite the fact that I was compiling (or at least it seemed so) for OS 3.0, so we should be normally be in the first part of the clause. It was then failing because the version of the method being called was not the proper one. When looking at the error in detail, especially the command line that was being called, this is what was being generated in the case of compiling with the simulator :
CompileC "build/AppShaker.build/Debug-iphonesimulator/AppShaker Lite.build/Objects-normal/i386/ASIHTTPRequest.o" Classes/ASIHttpRequest/ASIHTTPRequest.m normal i386 objective-c com.apple.compilers.gcc.4_2
cd /Users/loom/Documents/work/iphone/AppShaker
setenv LANG en_US.US-ASCII
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -x objective-c -arch i386 -fmessage-length=0 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -D__IPHONE_OS_VERSION_MIN_REQUIRED=20000 -isysroot /var/folders/95/95xwCQ0mEeivSCrcsKn1i++++TI/-Caches-/com.apple.Xcode.501/CompositeSDKs/iphonesimulator-iPhoneSimulator3.0-aljhdklevtyfaoefjftiofmwffte -fvisibility=hidden -mmacosx-version-min=10.5 -gdwarf-2 -iquote "/Users/loom/Documents/work/iphone/AppShaker/build/AppShaker.build/Debug-iphonesimulator/AppShaker Lite.build/AppShakerLite-generated-files.hmap" "-I/Users/loom/Documents/work/iphone/AppShaker/build/AppShaker.build/Debug-iphonesimulator/AppShaker Lite.build/AppShakerLite-own-target-headers.hmap" "-I/Users/loom/Documents/work/iphone/AppShaker/build/AppShaker.build/Debug-iphonesimulator/AppShaker Lite.build/AppShakerLite-all-target-headers.hmap" -iquote "/Users/loom/Documents/work/iphone/AppShaker/build/AppShaker.build/Debug-iphonesimulator/AppShaker Lite.build/AppShakerLite-project-headers.hmap" -F/Users/loom/Documents/work/iphone/AppShaker/build/Debug-iphonesimulator -I/Users/loom/Documents/work/iphone/AppShaker/build/Debug-iphonesimulator/include -I../fbconnect-iphone/src "-I/Users/loom/Documents/work/iphone/AppShaker/build/AppShaker.build/Debug-iphonesimulator/AppShaker Lite.build/DerivedSources/i386" "-I/Users/loom/Documents/work/iphone/AppShaker/build/AppShaker.build/Debug-iphonesimulator/AppShaker Lite.build/DerivedSources" -DLITE_VERSION -include /var/folders/95/95xwCQ0mEeivSCrcsKn1i++++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/AppShaker_Prefix-audfaisngyebyfexxpoauqdgjasw/AppShaker_Prefix.pch -c /Users/loom/Documents/work/iphone/AppShaker/Classes/ASIHttpRequest/ASIHTTPRequest.m -o "/Users/loom/Documents/work/iphone/AppShaker/build/AppShaker.build/Debug-iphonesimulator/AppShaker Lite.build/Objects-normal/i386/ASIHTTPRequest.o"
and when compiling for the device, I got the following command line :
CompileC "build/AppShaker.build/Debug-iphoneos/AppShaker Lite.build/Objects-normal/armv6/ASIHTTPRequest.o" Classes/ASIHttpRequest/ASIHTTPRequest.m normal armv6 objective-c com.apple.compilers.gcc.4_2
cd /Users/loom/Documents/work/iphone/AppShaker
setenv LANG en_US.US-ASCII
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -x objective-c -arch armv6 -fmessage-length=0 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O0 -Wreturn-type -Wunused-variable -isysroot /var/folders/95/95xwCQ0mEeivSCrcsKn1i++++TI/-Caches-/com.apple.Xcode.501/CompositeSDKs/iphoneos-iPhoneOS3.0-gxzvuzxhrjrauieejvpvjxrjejlf -fvisibility=hidden -gdwarf-2 -mthumb -miphoneos-version-min=2.0 -iquote "/Users/loom/Documents/work/iphone/AppShaker/build/AppShaker.build/Debug-iphoneos/AppShaker Lite.build/AppShakerLite-generated-files.hmap" "-I/Users/loom/Documents/work/iphone/AppShaker/build/AppShaker.build/Debug-iphoneos/AppShaker Lite.build/AppShakerLite-own-target-headers.hmap" "-I/Users/loom/Documents/work/iphone/AppShaker/build/AppShaker.build/Debug-iphoneos/AppShaker Lite.build/AppShakerLite-all-target-headers.hmap" -iquote "/Users/loom/Documents/work/iphone/AppShaker/build/AppShaker.build/Debug-iphoneos/AppShaker Lite.build/AppShakerLite-project-headers.hmap" -F/Users/loom/Documents/work/iphone/AppShaker/build/Debug-iphoneos -I/Users/loom/Documents/work/iphone/AppShaker/build/Debug-iphoneos/include -I../fbconnect-iphone/src "-I/Users/loom/Documents/work/iphone/AppShaker/build/AppShaker.build/Debug-iphoneos/AppShaker Lite.build/DerivedSources/armv6" "-I/Users/loom/Documents/work/iphone/AppShaker/build/AppShaker.build/Debug-iphoneos/AppShaker Lite.build/DerivedSources" -DLITE_VERSION -include /var/folders/95/95xwCQ0mEeivSCrcsKn1i++++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/AppShaker_Prefix-bgsrygfnnblyztcpvkeymcpfoigy/AppShaker_Prefix.pch -c /Users/loom/Documents/work/iphone/AppShaker/Classes/ASIHttpRequest/ASIHTTPRequest.m -o "/Users/loom/Documents/work/iphone/AppShaker/build/AppShaker.build/Debug-iphoneos/AppShaker Lite.build/Objects-normal/armv6/ASIHTTPRequest.o"
Then I looked at the system defininition for the __IPHONE_OS_VERSION_MIN_REQUIRED constant :
#ifndef __IPHONE_OS_VERSION_MIN_REQUIRED
#ifdef __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__
// compiler sets __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ when -miphoneos-version-min is used
#define __IPHONE_OS_VERSION_MIN_REQUIRED __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__
#endif
#endif
What is really interesting is that some nice engineer documented here in the comment that the environment constants comes from the -miphoneos-version-min command line option. So immediately I looked at the above command lines to figure out what the value was for those. In the case of the device compilation, indeed we can find it, and it's value is :
-miphoneos-version-min=2.0
In the case of the simulator, strangely it isn't generating the same command line and is instead directly defining the minimal OS version directly, as seen in the extract below :
-D__IPHONE_OS_VERSION_MIN_REQUIRED=20000
Why the two environment compile differently is still a mystery to me so if any readers can shed some light they are more than welcome.
When I saw the value being at minimal 2.0 I wondered where it could come from. I looked at my project build variables and I saw that I had multiple values for the IPHONEOS_DEPLOYMENT_TARGET variable, so I cleaned it up and removed all different levels. So basically this was what it looked like in the main project Info screen :
As it is NOT in bold, it means that the definition is using the default project compiler value, so I thought that was probably ok.
/* For iPhone OS, if no version number is specified, we default to
2.0. */
As this was the behavior I was seeing, I suspected that probably the default in the project info must not be correct. So I tried the following, which worked (!) : I went back to the project info, selected the "iPhone OS Deployment Target", the selected "iPhone OS 2.0" (or any different value, it doesn't matter, and then reselected "iPhone OS 3.0". This had the effect of making a definition at the project level, which is confirmed by the fact that the setting is now in bold, as illustrated below :
I then selected "Build -> Clean All Targets" and rebuilt all targets, and that was it !
So there it was, another obscure behavior of XCode. If others have this problem, please comment this blog entry, and I might then make a bug report to Apple, because this is really tricky to figure out.
Posted via email from Tofodo Software