关于Xcode 4创建静态库

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

QQ发布的微博SDK会报错,也是因为没有把静态库打包为unniver static libraries的原因,至于是什么是unniver static libraries,大家可以google一下。

  
  
  
  
  1. 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

  
  
  
  
  1. #import <Foundation/Foundation.h> 
  2.  
  3. @interface MyClass : NSObject {  
  4. }  
  5. - (int)add:(int)a b:(int)b;  
  6. @end 

.m

  
  
  
  
  1. #import "MyClass.h"  
  2.  
  3. @implementation MyClass  
  4. - (int)add:(int)a b:(int)b  
  5. {  
  6.     return (a + b);  
  7. }  
  8.  
  9. @end 

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

4、然后 Edit Scheme pane (Product > Edit Scheme), change its build configuration to Release,这样就产生一个release模式的静态库,注意release和debug模式的静态库是有区别,如果在引用并把这个模式调错,就会报出

  
  
  
  
  1. “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创建静态库详解的内容介绍完了,希望通过本文的学习能对你有所帮助!

你可能感兴趣的:(qq,Scheme,Google,xcode,Build)