The iPhone SDK: APIs Apple Didn't Want You to Know About
Pages: 1, 2, 3
Step 2: Build and install cross-compiler tools
The following commands build and install the cross-compiler components of the tool chain. These are specific to Mac OS X, so be sure to read the official documentation if you're using a different platform.
$ pushd iphone-dev
$ sudo mkdir /usr/local/arm-apple-darwin
$ mkdir -p build/odcctools
$ pushd build/odcctools
$ ../../odcctools/configure --target=arm-apple-darwin --disable-ld64
$ export INCPRIVEXT="-isysroot /Developer/SDKs/MacOSX10.4u.sdk"
$ make
$ sudo make install
$ popd
$ HEAVENLY=/usr/local/share/iphone-filesystem
Step 3: Install the low-level API headers
Because the iPhone's architecture is different from the desktop's, special headers need to be installed to access the low-level APIs of the iPhone. Issue the following commands to install them:
$ pushd include
$ ./configure
--with-macosx-sdk=/Developer/SDKs/MacOSX10.4u.sdk
$ sudo bash install-headers.sh
$ popd
Step 4: Install the Csu
The Csu provides C hooks into assembly's "start" entry point, and sets up the stack so that your program's main() function can be called. It's essentially glue code.
$ mkdir -p build/csu
$ pushd build/csu
$ ../../csu/configure --host=arm-apple-darwin
$ sudo make install
$ popd
Step 5: Build and install llvm-gcc
Now that the LLVM framework, cross-compiler tools, and Csu have been built, the compiler itself can now be built and installed. If you're doing this in stages or have since closed your Terminal window, make sure that you've still got the environment variables $LLVMOBJDIR and $HEAVENLY set to the proper directories. The LLVMOBJDIR variable points to the location of LLVM object files, which were compiled when you built LLVM. These are used to build llvm-gcc. The HEAVENLY variable points to the location where you copied the iPhone's libraries onto your desktop. This directory is used by llvm-gcc to nk to the iPhone's framework and library files when you compile applications. The name "Heavenly" was the code name given by Apple to the 1.0 code base of the iPhone software. The latest version (1.2) is named "Aspen," but the original name is still used in the tool chain. Both are named for ski slopes.
$ set
| grep -e LLVMOBJDIR -e HEAVENLY
If you don't see output from the previous command, you need to set the environment variables again. Get back into your build directory and run:
$ pushd
llvm-svn && LLVMOBJDIR=`pwd` && popd
$ HEAVENLY=/usr/local/share/iphone-filesystem
Once you've ensured that these are set, issue the following commands to build and install the compiler.
$ mv llvm-gcc-4.0-iphone/configure llvm-gcc-4.0-iphone/configure.old
$ sed \
's/^FLAGS_FOR_TARGET=$/FLAGS_FOR_TARGET=${FLAGS_FOR_TARGET-}/g' \
llvm-gcc-4.0-iphone/configure.old > llvm-gcc-4.0-iphone/configure
$ sudo ln -s /usr/local/arm-apple-darwin/lib/crt1.o \
/usr/local/arm-apple-darwin/lib/crt1.10.5.o
$ mkdir -p build/llvm-gcc-4.0-iphone
$ pushd build/llvm-gcc-4.0-iphone
$ export FLAGS_FOR_TARGET="-mmacosx-version-min=10.1"
$ sh ../../llvm-gcc-4.0-iphone/configure \
--enable-llvm=`llvm-config --obj-root` \
--enable-languages=c,c++,objc,obj-c++ \
--target=arm-apple-darwin --enable-sjlj-exceptions \
--with-heavenly=$HEAVENLY \
--with-as=/usr/local/bin/arm-apple-darwin-as \
--with-ld=/usr/local/bin/arm-apple-darwin-ld
$ make LLVM_VERSION_INFO=2.0-svn-iphone-dev-0.3-svn
$ sudo make install
$ popd
$ popd
Congratulations! You've built the free tool chain for iPhone. You're now ready to start compiling iPhone applications. The compiler itself can be invoked directly by calling /usr/local/bin/arm-apple-darwin-gcc.
When you build your applications for iPhone OS, you'll need to be sure to use the following additional CFLAGS:
CFLAGS = -fobjc-abi-version=2 \
-F/usr/local/share/iphone-filesystem/System/library/PrivateFrameworks
And LDFLAGS:
-lobjc
Resources
- iPhone Open Application Development -- book by Jonathan Zdziarski
- iPhone Open Application Development Forum -- Join conversations with author Jonathan Zdziarski, and other developers designing third-party software that will run on the iPhone
Jonathan Zdziarski is better known as the hacker "NerveGas" in the iPhone development community. His work in cracking the iPhone helped lead the effort to port the first open source applications, and his book, iPhone Open Application Development, taught developers how to write applications for the popular device long before Apple introduced its own SDK. Jonathan's website is zdziarski.com.
Return to ONLamp.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 5 of 5.
-
all I want is...
2008-06-25 14:32:24 macdob [Reply | View]
Hey, I'm not asking for much here (I hope!). All I want is serial port (or better yet, bluetooth) access so I can port my mac based telescope controller over to the iphone. That'd be sweet.
-
FUD
2008-03-29 15:03:10 John G. Cary [Reply | View]
This is so sad, you really seem to depreciate Apple's work on the SDK and spreading FUD just for the sake of selling your book.
Seriously, the toolchain is nice in the way it enables you to code something actually running on the current firmwares. However, it doesn't look polished at all contrary to what has been refactored into the official SDK.
So, in the end I really think Apple is keeping improving stuff and by June, currently missing features in the official SDK will be available - and at that point your book will be pretty useless and you know that right ?
-
Probably a less sinister explanation
2008-03-25 11:54:10 gregjor [Reply | View]
There's a less sinister explanation for Apple not publishing all of the iPhone APIs: Some of the undocumented functions will be changed in future releases that will break applications that use them. This has been Apple's policy with the Macintosh since 1984. Mac developers who used undocumented APIs had their apps break over and over, and the same will happen to iPhone developers.
Developers who write to unsupported APIs are free to do so, but you can't expect Apple to support those applications through iTunes, or take support calls from iPhone users who install a software update only to find your application no longer works for them.
Before accusing Apple of keeping secrets to prevent developers competing with them or restricting developer freedom, consider more mundane considerations, like developer support costs and maintaining the iPhone user experience.
Greg Jorgensen
MacDTS Thought Police, retired







I'm open-source minded and I would like to support the opensource development framework for iPhone proposed here and there : http://code.google.com/p/iphone-dev/
But I (and we) need some help with toolchain building.
a lot of people are stuck with llvm building or odcctool.
I'm stuck at the llvm step.
Using Fedora 10 x86_64
last bison, flex, gcc etc...
:(