Wednesday, January 20, 2010

Universal C/C++ Static Library for iPhone simulator and device using Xcode

In my previous post, I googled many articles to create universal static library by using shell script. However, here is a simple and easy way to create universal static library that can be used for both iPhone Simulator and device.

How to create universal C/C++ static library using Xcode
1. Create a new project using Xcode: iPhone OS->Application->OpenGL ES Application using Xcode (e.g., MathFuncsLib)
2. Delete all files from Classes
3. Delete "main.m" from Other Sources
4. Delete the current target "MathFuncsLib"
5. Create new static library target "MathFuncsLib"
6. Add your header (e.g., MathFuncsLib.h) and source (e.g., MathFuncsLib.cpp) files for MathFuncsLib into in Classes
7. Select active SDK: Simulator - your SDK version and Build (library file for x86 architecture)
8. Select active SDK: Device - your SDK version and Build (library file for arm architecture)
9. Find library files for each architecture under a build folder and change their file name appropriately. For example "MathFuncsLib-x86.a" and "MathFuncsLib-arm.a"
10. Copy them into any same folder
11. Create universal static library by running "lipo MathFuncsLib-x86.a MathFuncsLib-arm.a -create -output libMathFuncsLib-fat.a" in Terminal

How to use universal C/C++ static library in your iPhone application
1. Create your iPhone application
2. Open Info for Target, and on Build tab, add your library name for Linking->Other Linker Flags (you should use this format: -l[your library name]. In my case, -lMathFuncsLib-fat)
3. If you create separate folders for library such as "Include" for header files and "Lib" for library file, add them for Search Paths->Header Search Paths and Library Search Paths on the Build tab
4. Import header file for library in your application (e.g., #import "MathFuncsLib/MathFuncsLib.h")
5. Build and Go application
6. If you want to look at your application on iPhone device, you also need to follow the instruction to install your application on device by using "Apple Developer Program"


Anonymous said...


Manju NaIdu said...

By learning IOS you can able to create build views. You can handle user interaction via controls like buttons, switches, and sliders etc. We can also able to display data in a table view. You can create alert boxes, handle navigation and transition between views. You can also follow iOS App Development online Course India