iOS Development Tips
Objective-C Warppers
CGXPathQuery for Objective-C is a wrapper class for
NSXMLParser to query XML documents such as Web API responses with
XPath more easily. To know the project in more detail, please check
XPathQueryForObjC page.
Subversion for Objective-C
Subversion for Objective-C is a wrapper package of
Apache Subversion for MacOSX and iOS developers. To know the project in more detail, please check
SubversionForObjC page.
CyberLink for Objective-C is a wrapper package of
CyberLink for C for
UPnP™ developers. To know the project in more detail, please check
CyberLinkForObjC page.
XCode Command Line Utilities
xcode-select
xcode-select is a useful utility when you have to install multiple XCodes into a your MacOSX computer.
$ xcode-select --help
Usage: xcode-select -print-path
or: xcode-select -switch <xcode_folder_path>
or: xcode-select -version
Arguments:
-print-path Prints the path of the current Xcode folder
-switch <xcode_folder_path> Sets the path for the current Xcode folder
-version Prints xcode-select version information
Getting SDK Root Directory
Using the utility, you can get the current active SDK directory for iOS as the following.
$ echo `xcode-select -print-path`/Platforms/iPhoneOS.platform/Developer
/Developer/Platforms/iPhoneOS.platform/Developer
xcodebuild
xcodebuild is installed with XCode, and it is a useful command line tool to run XCode projects on the command line environment.
$ xcodebuild -help
Usage: xcodebuild [-project <projectname>] [-activetarget] [-alltargets] [-target <targetname>]...
[-parallelizeTargets] [-activeconfiguration] [-configuration <configurationname>]
[-sdk <sdkfullpath>|<sdkname>] [-xcconfig <filepath>] [<buildsetting>=<value>]... [<buildaction>]...
xcodebuild [-version [-sdk [<sdkfullpath>|<sdkname>] [<item>] ]
xcodebuild [-showsdks]
xcodebuild [-find <binary> -sdk <sdkfullpath>|<sdkname>]
xcodebuild [-list]
Running Unit Testing with CI Tools
To run
unit testing of XCode with continuous integration tools such as
Hudson, xcodebuild is a very useful tool to run the testing project on the command line.
$ xcodebuild -project CGApplication.xcodeproj -sdk iphonesimulator4.2 -target CGUnitTests -configuration Release
Getting Latest Available SDK Version
Using xcodebuild, you can check all available SDKs on your environment as the following.
$ xcodebuild -showsdks
Mac OS X SDKs:
Mac OS X 10.5 -sdk macosx10.5
Mac OS X 10.6 -sdk macosx10.6
iOS SDKs:
iOS 4.2 -sdk iphoneos4.2
iOS Simulator SDKs:
Simulator - iOS 3.2 -sdk iphonesimulator3.2
Simulator - iOS 4.0 -sdk iphonesimulator4.0
Simulator - iOS 4.1 -sdk iphonesimulator4.1
Simulator - iOS 4.2 -sdk iphonesimulator4.2
To get a latest SDK version, run the following script using the showsdk option.
$ xcodebuild -showsdks | grep iphoneos | sort | tail -n 1 | awk '{ print $2}'
4.2
Using Open Source Software for iOS
Compiling Open Source Software for UNIX using Configure Script
Traditionally, Open source projects for UNIX has a 'configure' script to make the projects. To run the configure script for iOS platforms, you have to set some environment variables and command line options as the following. To download the script file, please click
configure4ios.zip .
export DEVROOT="`xcode-select -print-path`/Platforms/iPhoneOS.platform/Developer"
export SDKVER=`xcodebuild -showsdks | grep iphoneos | sort | tail -n 1 | awk '{ print $2}' `
export SDKROOT="$DEVROOT/SDKs/iPhoneOS$SDKVER.sdk"
export PREFIX="/opt/ios-$SDKVER"
export ARCH="armv6"
export CC="$DEVROOT/usr/bin/gcc"
export CFLAGS="-arch $ARCH -isysroot $SDKROOT"
./configure \
--prefix="$PREFIX" \
--host="arm-apple-darwin" \
--enable-static \
--disable-shared $@
Using the above script, I think that you can make open source projects for UNIX with your iOS projects easily. However, you may have to set more environment variables or command line options if the configure script is created by elaborate configurations
Example : Compiling Apache Portable Runtime for iOS
According to
Cross-compiling the Apache Portable Runtime for the iPhone, I have updated the scripts and created the patches using Xcode 4.0 or 3.2.6 with iOS SDK 4.3. I have created the scripts for APR Utility too. The principal my environment is below.
| Xcode |
4.0 or 3.2.6 (GCC 4.2.1) |
| iOS |
4.3 |
| Apache Portable Runtime |
0.9.18 |
| APR Utility |
0.9.17 |
To compile APR and APR Utility for iOS, use
the configure scripts which are modified to latest XCode from
the original scripts as the following :-). Thanks for
Michael Safyan.
$ uname -a
Darwin mbair-skonno.local 10.6.0 Darwin Kernel Version 10.6.0: Wed Nov 10 18:13:17 PST 2010; root:xnu-1504.9.26~3/RELEASE_I386 i386
$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ tar xvfz apr-0.9.18.tar.gz
$ cd apr-0.9.18
$ ./apr-ios-configure
$ make
$ sudo make install
$ sudo patch -d /opt/ios-4.3/include/apr-0/ < apr_general-dev.diff
$ tar xvfz apr-util-0.9.17.tar.gz
$ cd apr-util-0.9.17
$ ./apr-ios-configure
$ make
$ cd uri/; gcc -o gen_uri_delims gen_uri_delims.c; ./gen_uri_delims; cd ..
$ make
$ sudo make install
GCC changes in XCode 4.0 and 3.2.6
From XCode 4.0 GM and XCode 3.2.6, I found some my configure scripts for iOS aborted with the following errors.
$ export CFLAGS=-std=c99 -arch armv6 --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk
-isystem /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/include
$ export LDFLAGS=-arch armv6 --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk
-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib
$ ./configure --host="arm-apple-darwin"
configure: WARNING: If you wanted to set the --build type, don't use --host.
If a cross compiler is detected then cross compile mode will be used.
checking build system type... i386-apple-darwin10.6.0
checking host system type... arm-apple-darwin
checking for arm-apple-darwin-gcc... /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc
checking for C compiler default output... configure: error: C compiler cannot create executables
According to the config.log, the configure script couldn't build the executable file because the linker couldn't found libcache for armv6.
$ less config.log
......
configure:xxxx: /Developer326/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -std=c99 -arch armv6
--sysroot=/Developer326/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk
-isystem /Developer326/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/include
-L/Developer326/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib
conftest.c >&5
ld: file not found: /usr/lib/system/libcache.dylib for architecture armv6
collect2: ld returned 1 exit status
configure:xxxx: $? = 1
configure:xxxx: result:
configure: failed program was:
| /* confdefs.h. */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| /* end confdefs.h. */
|
| int
| main ()
| {
|
| ;
| return 0;
| }
configure:xxxx: error: in `xxxx:
configure:xxxx: error: C compiler cannot create executables
......
I created a new sample library project using XCode 4.0 to check the problem, and check the build log. Then I found the XCode uses "-isysroot" option in the link phase. According to
GCC - Options for Directory Search, "--sysroot" option has a priority over "-isysroot", but it seems that "--sysroot" option is not working from XCode 4.0 and 3.2.6.
In any case, use '"-isysroot" option instead of "--sysroot" to run your configure scripts from XCode4 and 3.2.6