作者:舍得333 主页:http://blog.sina.com.cn/u/1509658847
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明,否则将追究法律责任。
参考的所有网址:(喜欢捣鼓的,最好看看那)
http://www.cnblogs.com/xiaodao/archive/2012/03/28/2422091.html
http://www.xiaojiayi.com/2012/08/15/xcode中的子项目(译文)/
http://blog.csdn.net/liutao6982/article/details/6928486
http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/
http://developer.apple.com/library/mac/#qa/qa1490/_index.html
http://kongbei888.blog.163.com/blog/static/24326613201307111415481/
下面属于随手笔记,还未好好整理,逻辑较混乱,仅供参考
在自己工程导入另一个工程,有点像导入静态库,只是有点像,如下图:
最好先学会静态库的生成,会很有帮助。
参考网址:http://www.xiaojiayi.com/2012/08/15/xcode中的子项目(译文)/
上面的文章有几点说的不是很到位,下面解释一下:
1.关于头文件的引入问题,上面的网址使用的方法是:
在工程的"Build Settings"里面使用搜索栏,搜索"User Header Search Paths",添入"recursive"
这种方法要求,子工程的文件夹 要放在 主工程文件夹下面,recursive就是再主工程文件夹下递归查找。
如果子工程文件 与 主工程文件夹 不是相互包含的关系,则上面的设置无效。
应该用如下方法代替:
在工程的"Build Settings"里面使用搜索栏,搜索"Header Search Paths",
添入子工程文件夹的绝对路径,就像“**子工程文件夹”。
2.对于子工程,如果在子工程文件夹下里面自己又乱建其它文件夹的话,这些自己建的文件夹下面的头文件都查找不到,要在上面的基础上,在加设置,添加 递归查找子文件夹
3.Header search paths 设置的另一种方法
设置为 $(BUILT_PRODUCTS_DIR)/include
这个路径会根据 debug 和release模式不同而不同,
同时,在子项目的 "build phases" 里面的“copy file”里面,把所有的头文件都加上。
注意
1. Other Linker Flags
build setting under the Linking collection and set its value to -ObjC
.
参考连接:http://developer.apple.com/library/mac/#qa/qa1490/_index.html
the target linking against the static library must pass the -ObjC
option to the linker. This flag causes the linker to load every object file in the library that defines an Objective-C class or category
Important: For 64-bit and iPhone OS applications, there is a linker bug that prevents -ObjC
from loading objects files from static libraries that contain only categories and no classes. The workaround is to use the -all_load
or -force_load
flags.
-all_load
forces the linker to load all object files from every archive it sees, even those without Objective-C code. -force_load
is available in Xcode 3.2 and later. It allows finer grain control of archive loading. Each -force_load
option must be followed by a path to an archive, and every object file in that archive will be loaded.
2.“User Header Search Paths” 和 “Header Search Paths”
参考链接:http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/
User Header Search Paths set
The “User Header Search Paths” setting defines the headers available as quoted imports (eg “#import “MyLibraryClass.h”) while the “Header Search Paths” setting defines those headers available as bracketed imports (eg “#import ). I’ve found that Xcode will only autocomplete header names in the quoted form so I always add libraries to the user header search path even though, from my project’s perspective, they might be more appropriate as system level (angle bracketed) libraries.
When using a static library which includes categories we will also have to add the “-ObjC” flag to the “Other Linker Flags” build setting. This will force the linker to load all objective-c classes and categories from the library. If the library contains only categories “-all_load” or “-force_load” may be needed as well. See Technical Q&A QA1490 for a more detailed explanation of these settings.
3.注意:在ios5以及以上版本中,引入别的工程(如上)或者静态库,
并且StoryBoards中使用了【引入的外部类(外部工程或者静态库里面的类)】,
那么Other Linker Flags 里面必须加上-ObjC,否则,会console会报错
error:Unknown class <外部的类名> in Interface Builder file.
引用:
http://developer.apple.com/library/mac/#qa/qa1490/_index.html
Important: For 64-bit and iPhone OS applications, there is a linker bug that prevents
-ObjC from loading objects files from static libraries that contain only categories and no classes. The workaround is to use the
-all_load
or
-force_load
flags.
上面的意思是说
对于64位操作系统或者ios系统,-Objc存在一个bug,就是只包含categories ,而没有任何class的静态库,是不会被加载进来。
拮据额这个bug:使用标识符:
-all_load 或者
-force_load