Building applications for iOS is always done using XCode. The XCode application comes with a number of tools that are used at various stages of the development process. One of those tools is a native C/C++ compiler based on clang which can be run from the command line. When XCode is installed, the clang compiler is added to the ‘/usr/bin’ folder, so it can be run from anywhere without a full path just by typing ‘clang’. The XCode clang compiler supports all of the various architectures that iOS runs on through the ‘-arch’ flag, and it must be pointed to a system root folder where all of the iOS system includes and libraries can be found through the ‘-isysroot’ flag. The system root folder changes with each version of XCode. For convenience, XCode makes a symlink to the latest version which can be used by build systems. For a default installation of XCode, the symlink should be:
This can be used by build systems (e.g. makefiles) when invoking the clang compiler.
When developing native libraries for iOS, both static and dynamic libraries are supported. In each case, the library must be built multiple times, once for each architecture that will be supported. Once all the libraries are built, they can be combined into a single library file that supports all of the architectures. XCode installs the ‘lipo’ tool for this. The following makefile example shows how to build a simple static library for iOS using ‘clang’ and ‘lipo’:
foo.a: foo_arm64.o foo_armv7.o
lipo -create -output [email protected] $^
clang -arch arm64 -isysroot $(SDKROOT) -c -o [email protected] $^
clang -arch armv7 -isysroot $(SDKROOT) -c -o [email protected] $^