- 添加static library project
右击项目A,在弹出菜单中选择”Add Files to“,选择对应的.xcodeproj文件即可。或者直接把这个static library project的.xcodeproj拖拽到项目A中。
弄完后,static library project应该被自动打开了,如果没有,它就是被另外一个xcode 窗口中被打开了,必须先关闭掉,然后在项目A中打开。
- 添加build 依赖
在Targets->build Phases->Link Binary with Libraries 添加刚才的static library
- 添加static library的头文件
在Targets->build settings->user header search paths设置static library的头文件搜索路径
其中要用到的一些xcode预定义变量,可以参考http://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html
- 如果项目A是non-arc,而static library是arc的,则需要以下操作
不能直接通过源文件进行编译,只能作为static library进行link
在Targets->build settings->build option 将LLVM GCC 4.2 改为Apple LLVM compiler 3.0
对使用了arc的源文件,在Targets->Build Phases->Compile Sources, 点击对应的源文件,添加编译选项-fobjc-arc
参考http://blog.cnrainbird.com/index.php/2012/03/13/object-c_kai_fa_zhong_hun_he_shi_yong_huo_bu_shi_yong_arc/ - static library里面有category, 在你的项目中使用这个category时,需要设置一个flag,否则category不会被连接进去
Targets->build settings->other Linker Flags , 添加-ObjC, 否则category不可用,最后运行的时候会出错
参考http://stackoverflow.com/questions/932856/calling-method-on-category-included-from-iphone-static-library-causes-nsinvalida - 添加linker flags需要注意的事项
Debug, Release, Any Architecture版本的,需要弄清楚你现在build的是哪个版本,然后在上面设置准确选项,一般把Any Architecture的去掉
之前在移植的时候,在Debug跟Release上设置了-fobjc-arc,但Any Architecture上没有设置,导致没有正确的link,最后删掉Any Architecture就行了
xcode添加static library project
最新推荐文章于 2024-03-25 22:26:08 发布