您的位置:首页 > 其它

关于Xcode 4创建静态库

2011-09-25 15:33 375 查看
Xcode 4创建静态库详解是本文要将介绍的内容,主要是为了代码保密或者代码重用等等原因需要把现有的代码打包放入静态库中,这也是静态库的好处,所以今天一天都在研究如何用xcode 4创建静态库,也是为了我们的项目需要。

QQ发布的微博SDK会报错,也是因为没有把静态库打包为unniver static libraries的原因,至于是什么是unniver static libraries,大家可以google一下。
http://blog.boreal-kiss.net/2011/03/15/how-to-create-universal-static-libraries-on-xcode-4/


下面是创建静态库的方法

1、xcode-create project-cocoa touch static libary.这样就顺利的创建了一个静态库模板。里面只有一个文件,没有什么用处。

2、在静态库中创建一个类,命名为MyClass。这样我们就得到了.h 和 .m 文件。

3、写入方法

.h
#import <Foundation/Foundation.h>

@interface MyClass : NSObject {
}
- (int)add:(int)a b:(int)b;
@end


.m
#import "MyClass.h"

@implementation MyClass
- (int)add:(int)a b:(int)b
{
return (a + b);
}

@end


方法很简单,如果你还是看不懂,就不要向下面看了。

4、然后 Edit Scheme pane (Product > Edit Scheme), change its build configuration to Release,这样就产生一个release模式的静态库,注意release和debug模式的静态库是有区别,如果在引用并把这个模式调错,就会报出
“ignoring file /Users/laiqiangzhuo/Desktop/TestLibary/TestLibary/libLibary.a, missing required architecture i386 in file“


的错误。

5、然后在主目录下找到/build/Release-iphoneos/libLibary.a文件,并把它拖到要使用它的project中。

6、在project中引用MyClass.h文件。

小结:关于Xcode 4创建静态库详解的内容介绍完了,希望通过本文的学习能对你有所帮助!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: