3rd party libraries used by iPhone applications are required to be linked statically. In order to build such a library for the device and simulator you need to set up your environment such that it will cross compile for the two different environments. This is as simple as using the following set of ‘exports’ as defined below.

# Defines to set up environment
export DEVROOT=${ROOTDIR}/Platforms/${PLATFORM}.platform/Developer
export SDKROOT=${DEVROOT}/SDKs/${PLATFORM}${MAX_VERSION}.sdk
export CC=$DEVROOT/usr/bin/gcc
export LD=$DEVROOT/usr/bin/ld
export CPP=$DEVROOT/usr/bin/cpp
export CXX=$DEVROOT/usr/bin/g++
export AR=$DEVROOT/usr/bin/ar
export LIBTOOL=$DEVROOT/usr/bin/libtool
export AS=$DEVROOT/usr/bin/as
export NM=$DEVROOT/usr/bin/nm
export CXXCPP=$DEVROOT/usr/bin/cpp
export RANLIB=$DEVROOT/usr/bin/ranlib
export OPTFLAG="-O${OPT}"
export COMMONFLAGS="${ARCH} -pipe $OPTFLAG -gdwarf-2 -no-cpp-precomp -mthumb -isysroot ${SDKROOT} -miphoneos-version-min=${MIN_VERSION}"
export LDFLAGS="${COMMONFLAGS} -L${HOME}${SDKROOT}/usr/lib"
export CFLAGS="${COMMONFLAGS} -fvisibility=hidden"
export CXXFLAGS="${COMMONFLAGS} -fvisibility=hidden -fvisibility-inlines-hidden"

This uses a few defines which need to be different for the device vs. simulator. Below are what you might want to use for each one. Note that MIN_VERSION, MAX_VERSION and OPT can all be set to control what SDK versions and the level of optimisation is used.

Device:

# Variables
export ROOTDIR="/Developer"
export PLATFORM="iPhoneOS"
export ARCH="-arch armv6 -arch armv7"
export MIN_VERSION="3.1"
export MAX_VERSION="4.0"
export OPT="3"

Simulator:

# Variables
export ROOTDIR="/Developer"
export PLATFORM="iPhoneSimulator"
export ARCH="-arch i386"
export MIN_VERSION="3.1"
export MAX_VERSION="4.0"
export OPT="3"

Once you have set the environment, you just need to use ‘make’ to build the library. If the library is using autoconf, then you will need to use the following ‘./configure’ options:

Device:

./configure --host=arm-apple-darwin9 --prefix=${HOME}/${SDKROOT} --enable-shared=no --disable-dependency-tracking

[Note: --disable-dependency-tracking is required because gcc can't use dependency tracking when building for 2 architectures at the same time (i.e. armv6 and armv7).]

Simulator:

./configure --host=i386-apple-darwin --prefix=${HOME}/${SDKROOT} --enable-shared=no

Then just use ‘make’ and ‘make install’ to build the library! It really is as easy as that :-D .

[Other libraries may require other configure options, but I can't cover them all here as they are often different]

EDIT: I’ve edited the defines above to be a bit clearer and factor out the common bits from the device/simulator.

Compiling Boost for the iPhone

November 10th, 2009

Updates:
boost-1.44:
For compiling Boost 1.44 please see my new post.

For a recent project I’ve had to compile the Boost C++ library for the iPhone. Much of the Boost library is header files so they are fine as nothing needs to be done, they just get copied into place, but the bits which do need compiling are a bit trickier. So I thought I’d share my experiences here.

First you need to download Boost (I went for version 1.40) from http://www.boost.org. Then you need to edit some of the Boost.Jam configuration. This involves creating a user-config.jam file in your home directory like so:

~/user-config.jam:
using darwin : 4.2.1~iphone
   : /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6
   : <striper>
   : <architecture>arm <target-os>iphone <macosx-version>iphone-3.0
   ;

using darwin : 4.2.1~iphonesim
   : /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386
   : <striper>
   : <architecture>x86 <target-os>iphone <macosx-version>iphonesim-3.0
   ;

Then edit tools/build/v2/tools/darwin.jam and add in the following under the macosx-versions variable:

.macosx-versions =
    10.6 10.5 10.4 10.3 10.2 10.1
    iphone-3.1 iphonesim-3.1
    iphone-3.0 iphonesim-3.0
    iphone-2.3 iphonesim-2.3
    iphone-2.2 iphonesim-2.2
    iphone-2.1 iphonesim-2.1
    iphone-2.0 iphonesim-2.0
    iphone-1.x
    ;

Then, you need to use the following lines to build Boost for iPhoneOS and iPhoneSimulator respectively:

./bjam --prefix=~/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr toolset=darwin architecture=arm target-os=iphone macosx-version=iphone-3.0 define=_LITTLE_ENDIAN link=static include=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr/include/c++/4.2.1/armv6-apple-darwin9 install
./bjam --prefix=~/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr toolset=darwin architecture=x86 target-os=iphone macosx-version=iphonesim-3.0 link=static include=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/include/c++/4.2.1/i686-apple-darwin9 install

It’s worth noting that at this stage everything will compile for the simulator but not for the device. This is because the device is missing two header files – ‘bzlib.h’ and ‘crt_externs.h’. To make it compile for the device simply copy these files from ‘/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/include/’ into your Boost folder and then everything should compile fine. I have no idea why Apple have omitted these header files from the device. The libraries are there, just the header files missing. I’ve created a bug on Radar for this, so please also do the same if you encounter this problem such that Apple will listen and include them.

That installs the files in ‘~/Developer/Platforms/iPhone(OS|Simulator).platform/Developer/SDKs/iPhone(OS|Simulator)3.0.sdk/usr’ which was where I wanted mine to go, but feel free to change that to wherever you want the libraries to end up. I did it this way because I created a custom SDK and then include that from iPhone projects within XCode.

boost-1.42:
Since Boost has been updated, I thought I’d extend this article to explain how to compile boost-1.42 for the iPhone. Boost themselves have gone a long way to do everything for you now, so there’s much less that needs to be done. You now need to do this:

~/user-config.jam
using darwin : 4.2.1~iphone
   : /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv7 -mthumb -fvisibility=hidden -fvisibility-inlines-hidden
   : <striper>
   : <architecture>arm <target-os>iphone <macosx-version>iphone-3.1.3
   ;

using darwin : 4.2.1~iphonesim
   : /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -fvisibility=hidden -fvisibility-inlines-hidden
   : <striper>
   : <architecture>x86 <target-os>iphone <macosx-version>iphonesim-3.1.3
   ;

Then edit tools/build/v2/tools/darwin.jam and add in the following under the macosx-versions variable:

tools/build/v2/tools/darwin.jam
## The MacOSX versions we can target.
.macosx-versions =
    10.6 10.5 10.4 10.3 10.2 10.1
    iphone-3.2 iphonesim-3.2
    iphone-3.1.3 iphonesim-3.1.3
    iphone-3.1.2 iphonesim-3.1.2
    iphone-3.1 iphonesim-3.1
    iphone-3.0 iphonesim-3.0
    iphone-2.2.1 iphonesim-2.2.1
    iphone-2.2 iphonesim-2.2
    iphone-2.1 iphonesim-2.1
    iphone-2.0 iphonesim-2.0
    iphone-1.x
    ;
# <grab source from boost.org>
tar xzf boost_1_42_0.tar.gz
cd boost_1_42_0
./bootstrap.sh

# Install for device:
./bjam --prefix=${HOME}/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/usr toolset=darwin architecture=arm target-os=iphone macosx-version=iphone-3.1.3 define=_LITTLE_ENDIAN link=static install

# Install for simulator
./bjam –-prefix=${HOME}/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.3.sdk/usr toolset=darwin architecture=x86 target-os=iphone macosx-version=iphonesim-3.1.3 link=static install

In-app Purchase on Free Apps

October 16th, 2009

Apple have announced the ability to allow in-app purchase on free apps. This is an interesting feature in my opinion. It will allow for some annoying “lite” versions which hide paid-for features which you have to pay to unlock, but also it will allow developers to leverage some interesting sales techniques.

This is one of the most exciting things I have seen Apple do over the past couple of months!

Mark my word: Tablet, May, 2010

LiDG 7th October 2009

October 8th, 2009

Yesterday, there was the monthly LiDG (London iPhone Developer Group) meet-up in the Apple Store, Regent Street. This month Ian Thain decided to allow developers to present for 1 minute (strictly!) about their apps. I chose to give a quick talk about BeerMap, giving the people there a quick run down on why they should download BeerMap and review some beers with it!

It seemed to get good feedback and along side other apps such as CurryFinder it was probably one of the most fun apps being showcased. I really enjoyed telling people about it and I hope that people will have downloaded and started using the app from seeing my presentation!

Below is a little photo of me presenting!
Matt Presenting at LiDG 7th October 2009

I found an article by Andrew Nusca on ZDNet which caught my eye. He gives 5 points as to why Android will beat other smartphones. I’d like to comment on them:

* Google backs Android, a major pipeline for its cloud services.
Yes, true, but Apple backs the iPhone and clearly has cloudy things in the pipeline with it’s building of a new billion dollar data centre.

* Android is improving rapidly. The Cupcake 1.5 release was well-received, and Donut 1.6 has already been sent over the air to handset owners.
iPhone OS is improving all the time as well. Granted Android is faster, but for developers I think it’s great how Apple release iPhone OS. It means you have time to get ready for each release to make sure all apps work properly on each version.

* Android is open, making it easier to quickly gain developers’ support.
The iPhone SDK is free to download and only £59 to become a member of the full developer program. It’s really not that much of a barrier.

* Android will run on phones from several manufacturers, which will help it quickly spread through the marketplace. HTC, Motorola and Samsung are already supporting handsets.
This is a bad thing in my opinion. I absolutely love the fact that with the iPhone you know exactly what devices the app will run on, and you know every exact specification. Only if the hardware manufacturer is the SDK provider, can this happen 100%.

* Android combines the best of what’s out there. It’s open, but it offers iPhone-like menus and apps, with Windows Mobile-esque icons, with Palm Pre-like multitasking. There’s another arms race afoot — the battle among Android handset makers as to which company can squeeze the most out of the OS.
Is that a good thing to mix-and-match? I prefer having a rock solid, stable OS, built by one of the best software companies in the world. Furthermore, they build the hardware as well so they know how to eek every last bit of power out of the hardware to provide software developers with one of the best platforms to develop for.

I Like Competition!

September 9th, 2009

Every now and then I check for the competition of Subnet Calc and Subnet Calc Pro on iTunes. Today I found a couple of new ones called IPSubnet and ITcalc4. Now, I don’t want to be rude but these just don’t seem as easy to use as Subnet Calc and what’s more, they both cost 59p / 99c whereas Subnet Calc is FREE! Granted, Subnet Calc Pro costs some money but I am hoping to always have the free version there for people who just want a quick and easy subnet calculator on their device.

Comments are welcomed for any points you have to make about Subnet Calc or any of its competitors.

UITableViewCell Geometry

August 25th, 2009

I keep needing to find this out, so I thought I’d post it here so I can refer to it. This is the geometry of the UILabels for each of the UITableViewCellStyles:

UITableViewCellStyleValue2
textLabel: 10.000000 : 14.000000 : 68.000000 : 16.000000
detailTextLabel: 83.000000 : 12.000000 : 207.000000 : 0.000000

Subnet Calc Sales

August 20th, 2009

I thought I’d post the latest stats I have for my sales of Subnet Calc:

Subnet Calc Sales

Notice that there is a distinct jump towards the present. This was when I switched category from Utilities to Business. I thought it was quite surprising that it made such a difference just changing category, but it seems to have made a fair difference.

I had the need to code sign using a different developer accounts and my initial thoughts were that it was going to be tricky. But it seems that Apple have actually made it easy now!

The problem comes that during code-sign, it searches for certificates by the name, which leads to “iPhone Developer: Matthew Galloway” matching both certificates you have installed (one for each developer account). But Apple have at some point changed their certificate signing process and they add a number of the end of the common name on the certificate. This means that each certificate is unique even if it’s for the same physical developer.

One thing to note is that I used the same private key to generate the CSR for both certificates. I’m not sure what the implications would be for using separate private keys, but I can’t imagine it would make a difference.

I guess Apple had to do this really because lots of companies would have ended up with problems I’m sure.

So for anyone wondering if they can use multiple developer certificates, then just go for it, it should work!

I estimate I am between 2 and 4 days from reaching my next monetary target which I set myself for my apps. To mark this occasion I have decided to do something which Malcolm Barclay talked about at the last iPhone and Smartphone Publishers and Developers meet up. It’s nothing too exciting, just I want to give it a try!

In other news I currently have 5, yes FIVE, apps in review with Apple. I’ve been quite busy over the past couple of weeks as I’ve been between jobs. I’ve released updates to 4 apps (another update to Subnet Calc Pro off the back of comments from users) and 1 completely new app which will be interesting for anyone out there who uses a Zen Internet broadband connection!

I’m continually impressed by Apple’s ability to keep the iPhone platform going so strong. It would be interesting to try doing it full time, but I don’t want to take that risk at the moment as I can’t guarantee I’d have enough money coming in and I actually am very much looking forward to starting my new job on Monday!

UPDATE:
Well I reached it! And I have now almost reached my next target! I also have released the app for Zen broadband customers, it’s called ZeBbUs (Zen Broadband Usage) and it lets you know how much of your Zen broadband plan you have used this month.