Building c++ static library for iPhone

It is a good idea to use c++ static library in a iPhone project, for xcode always need rebuild all files once a while ( Even if I modify only cpp file, I don't know why :( ).The way is simple but there are some points to notice.
1) You should build both simulator and os version. Commonly, you will have four libraries:Debug-iphoneos,Debug-iphonesimulator,Release-iphoneos,and Release-iphonesimulator.
2) How to build static library? Just add a new target with the type static library, and add all relative code files into the target, set the build options and build.
3) A word about device version. You should use code sign when build device version.
4) A word about SDK version. Initially, I use a beta version of iphone sdk, and it can not build device version of libaray but can build app. After I update to the final sdk, everything is OK.
5) How to link with library? Add the library file - with extension ".a"- to frameworks, set the library search path to the library, and use #pragma comment( lib, "xxx.a" ) in your code. You should make separate build config for device and simulator version, for they use different library. so I have four configuration: debug, release, debug_iphone, release_iphone. And there is still a problem for me: the library added to framework is the same to all configurations, I add the debug library to framework, and I cann't change it to release version in release config. I use different library search path to solve this problem, it seems OK. For release config, it will use release version library although the library added to framework is debug version.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值