本文旨在说明静态库制做中的一些常见问题和特殊处理 1. 打包静态库须要的相关问题和设置c++
Other Linker Flags
为-ObjC
或者-all_load
NSClassFromString
或者runtime
的objc_getClass
,可是转换出来的Class
一直为nil
。解决方法:在主工程的Other Linker Flags
须要添加参数-ObjC
便可public
了Base SDK
指的是当前编译所用的SDK 版本,通常默认为当前xocde的最新版Build Active Architecture Only
设置成No
Deployment Target
它控制着运行应用须要的最低操做系统版本Skip Install
设置为Yes
Mach-O Type
静态库设置为Static Library
,动态库设置为Dynamic Library
,制做bundle
文件设置为Bundle
xib
,要用的话就将xib
放到bundle
文件中编译,而后xib
就会变成.nib
的文件C
或者C++
,在使用的时候须要添加libc++.tbd
或者libstdc++.tbd
Implicit declaration of function ‘XXXX’ is invalid in C99
警告:**C语言是过程化的编程语言,程序执行顺序是从上到下。若是在调用某函数的时候,函数在调用以前没有定义也没有声明,而是在调用以后定义,那么编译时Implicit declaration of function ‘XXXX’ is invalid in C99
警告就产生了。这是有别于面向对象编程语言的地方2. framework中Optional和Required的区别git
Social.framework
和AdSupport.framework
,是在iOS 6以后才被引入的,更新了一些新的特性,若是运行在5.0甚至更低的设备上,这些库不支持,会编译通不过,这时候就要使用弱引用了dyld:Library not found ……
说明你可能使用了不应有的强引用,根据日志将这个库的引用形式修改一下;或者是使用了动态库,就须要在Embeded Binaries
选项中添加这个动态库3. 如何看一个framework中的二进制文件是静态库仍是动态库github
$ file /Users/yostar/Desktop/ProjectTest/YostarSDK/ThirdPath/TwitterKit.framework/TwitterKit
;见下面的截图,一个是静态库,一个是动态库
4. 查看静态库是否支持bitcode $ otool -l /Users/yostar/Desktop/UnityLib/libYostarSDK.a | grep __LLVM
若是上述命令的输出结果有__LLVM
,那么就说明,所用的framework
或.a
支持设置Enable bitcode
为YES
,不然不支持编程
5. 静态库相关操做xcode
$ lipo -info ./XXXX.a
$ lipo -info ./XXXX.framework/XXXX
复制代码
$ lipo -create XXXX_iphoneos.a XXXX_iphonesimulator.a -output XXXX_all.a
$ lipo -create XXXX_iphoneos.framework/XXXX_iphoneos XXXX_iphonesimulator.framework/XXXX_iphonesimulator -output XXXX_all
复制代码
$ lipo -thin libname.a armv7(CPU架构名称) -output libname-armv7.a
$ lipo -thin XXXX.framework/XXXX arm64 -output XXXX.framework/XXXX-arm64
复制代码
6. 打包framework之嵌套另外一静态库产生类文件重复问题 将打包好的framework和第三方静态库引入项目,运行,产生两个静态库文件类名重复的问题。以下:bash
7. 打包 C,C++文件及和OC混编,接口代码架构
C
代码 xcode新建文件YostarUtilits.h
和YostarUtilits.m
,例子以下:#import <Foundation/Foundation.h>
const char * getIDFA();
@interface YostarUtilits : NSObject
@end
复制代码
#import "YostarUtilits.h"
const char * getIDFA(){
NSString *str = @"123";
const char *strC = [IDFAStr UTF8String];
char *result = (char *)calloc(10, sizeof(char *));
if (result) {
strcpy(result, strC);
}
return result;
}
@implementation YostarUtilits
@end
复制代码
C++
代码 xcode新建文件YostarUtilits.h
和YostarUtilits.mm
,例子以下:#import <Foundation/Foundation.h>
@interface YostarUtilits : NSObject
@end
复制代码
#import "YostarUtilits.h"
#if defined(__cplusplus)
extern "C"
{
#endif
const char * getIDFA(){
NSString *str = @"123";
const char *strC = [IDFAStr UTF8String];
char *result = (char *)calloc(10, sizeof(char *));
if (result) {
strcpy(result, strC);
}
return result;
}
#if defined(__cplusplus)
}
#endif
@implementation YostarUtilits
@end
复制代码
附:个人博客地址框架