Compiling c programs for arm architecture/iOS on OSX

Compiling c programs for arm architecture/iOS on OSX

Lets start with C language compiler. xcrun is good command to find out the specific about the system and what sdk version is install, platform and other good stuff that you woul...

Alok Choudhary
Austin, TX
2 min read

Lets start with C language compiler. xcrun is good command to find out the specific about the system and what sdk version is install, platform and other good stuff that you would need in process.

xcrun -find -sdk iphoneos clang

Below are few variation of command with different available switch. Feel free to try

xcrun -find -sdk iphoneos clang xcrun -find -sdk iphoneos xcrun -find -sdk iphoneos —show-sdk-version xcrun -find -sdk iphoneos —show-sdk-version —show-sdk-platform-path xcrun -find -sdk iphoneos —show-sdk-version —show-sdk-platform-path —show-sdk-platform-version

Help switch can give you more details about xcrun

xcrun —help

Following command will give you where is clang compiler

XXX-mbp:XXX$ xcrun -find -sdk iphoneos clang

/Applications/Xcode511.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang

Following command will give you SDK Platform path as that would be helpful to determine SDKROOT while compiling C code for arm.

XXX-mbp:XXX$ xcrun -find -sdk iphoneos —show-sdk-platform-path

/Applications/Xcode511.app/Contents/Developer/Platforms/iPhoneOS.platform

These are the basic component that we need, but it would great if we setup these as environment variable so that in future we need not to worry about what is where. edit/make .profile in your home directory.

cd ~ ; vi .profile

CLANG=“/Applications/Xcode511.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang”

export CLANG

PLATFORM=“/Applications/Xcode511.app/Contents/Developer/Platforms/iPhoneOS.platform”

export PLATFORM

SDKROOT=$PLATFORM/Developer/SDKs/iPhoneOS7.1.sdk

(Remember that SDK version would change in future as so change these Environment variable accordingly)

Save the file and source it as

. ./profile

Now you are all set to compile your hello world program. write hello.c program and compile as follows

$CLANG -arch armv7 -isysroot $SDKROOT -o hello hello.c

It should generate binary file called hello.

XXX-mbp:XXX$ file hello

hello: Mach-O executable arm

if it says executable arm. ye ye you have just compile iOS command line program.

Happy coding.

Link copied to clipboard!

Made with ❤️ in Austin.

Copyright © 2026