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.
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.
本文介绍如何在iPhone项目中使用C++静态库来优化构建过程,避免每次修改C++文件时都需要重新编译整个项目。文章详细说明了为模拟器和设备构建不同版本的静态库的方法,并提供了具体的步骤指导。
468

被折叠的 条评论
为什么被折叠?



