Xcode引入另一個工程


作者:舍得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/


下面屬於隨手筆記,還未好好整理,邏輯較混亂,僅供參考


在自己工程導入另一個工程,有點像導入靜態庫,只是有點像,如下圖:
最好先學會靜態庫的生成,會很有幫助。

xcode <wbr>導入另一個工程

參考網址:http://www.xiaojiayi.com/2012/08/15/xcode中的子項目(譯文)/

上面的文章有幾點說的不是很到位,下面解釋一下:
1.關於頭文件的引入問題,上面的網址使用的方法是:
在工程的"Build Settings"里面使用搜索欄,搜索"User Header Search Paths",添入"recursive"
這種方法要求,子工程的文件夾 要放在 主工程文件夾下面,recursive就是再主工程文件夾下遞歸查找。

如果子工程文件 與 主工程文件夾 不是相互包含的關系,則上面的設置無效。
應該用如下方法代替:
在工程的"Build Settings"里面使用搜索欄,搜索"Header Search Paths",
添入子工程文件夾的絕對路徑,就像“**子工程文件夾”。

2.對於子工程,如果在子工程文件夾下里面自己又亂建其它文件夾的話,這些自己建的文件夾下面的頭文件都查找不到,要在上面的基礎上,在加設置,添加 遞歸查找子文件夾

xcode <wbr>導入另一個工程

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
 
-ObjC,This flag causes the linker to load every object file in the library that defines an Objective-C class or category
意思是,使用這個標識,會把靜態庫中,定義了Objective-C class的文件或者定義了category類別的文件,全部加載進來。
因為你的靜態庫里面擴展了一個已存在的類的category,那么這個category是不會加載進來的。
在程序運行中,調用此類別的方法,就會報錯“selector not recognized”。
 
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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM