自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

修改Xcode配置并支持iPhone上dylib工程 實(shí)例

移動(dòng)開(kāi)發(fā) iOS
本文介紹的是修改Xcode配置并支持iPhone上dylib工程,一篇不錯(cuò)的文章,與大家分享一下。先來(lái)看內(nèi)容。

修改Xcode配置并支持iPhonedylib工程是本文要介紹的內(nèi)容,逛壇子發(fā)現(xiàn)一篇好文章,與大家分享一下,先來(lái)看內(nèi)容。此帖純粹討論怎樣更改xcode配置來(lái)使其支持創(chuàng)建iphone上的dylib工程文件,不涉及任何其他破解話(huà)題!

測(cè)試機(jī)器:10.6 with Xcode3.2

最近在研究如何創(chuàng)建iphone上的dylib文件,google出來(lái)的都是toolchain的東西,使用makefile來(lái)編譯的,像我這種習(xí)慣IDE的人來(lái)說(shuō)非常之不爽,所以花了一天時(shí)間來(lái)破解了下Xcode來(lái)讓它可以創(chuàng)建編譯iphone上的dylib文件的工程。

簡(jiǎn)單說(shuō)下分析思路吧

首先xcode支持創(chuàng)建iphone static libtary和Cocoa的dynamic linrary的工程,通過(guò)不同編譯對(duì)比可以發(fā)現(xiàn)Xcode通過(guò)productType = "com.apple.product-type.library.dynamic";配置來(lái)確定工程類(lèi)型的。

打開(kāi)**.xcodeproj/project.pbxproj文件,搜索productType=定位,可以發(fā)現(xiàn)如下圖所示的內(nèi)容

[attachment=10545]

可以創(chuàng)建一個(gè)iphone的static工程把static改成dynamic編譯看看,可以發(fā)現(xiàn)xcode提示不支持dynamic類(lèi)型的工程,無(wú)法編譯,那我們讓他支持就好了。

我們需要修改以下文件

  1. /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Specifications/iPhoneOSProductTypes.xcspec  
  2. /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Specifications/iPhoneOSPackageTypes.xcspec  
  3. 在iPhoneOSProductTypes.xcspec中添加下列片段  
  4.  
  5. // Dynamic library  
  6.     {   Type = ProductType;  
  7.         Identifier = com.apple.product-type.library.dynamic;  
  8.         Class = PBXStaticLibraryProductType;  
  9.         Name = "Dynamic Library";  
  10.         Description = "Dynamic library";  
  11.         IconNamePrefix = "TargetLibrary";  
  12.         DefaultTargetName = "Dynamic Library";  
  13.         DefaultBuildProperties = {  
  14.             FULL_PRODUCT_NAME = "$(EXECUTABLE_NAME)";  
  15.             MACH_O_TYPE = "mh_dylib";  
  16.             REZ_EXECUTABLE = YES;  
  17.             EXECUTABLE_PREFIX = "";  
  18.             EXECUTABLE_SUFFIX = ".$(EXECUTABLE_EXTENSION)";  
  19.             EXECUTABLE_EXTENSION = "dylib";  
  20.             PUBLIC_HEADERS_FOLDER_PATH = "/usr/local/include";  
  21.             PRIVATE_HEADERS_FOLDER_PATH = "/usr/local/include";  
  22.             INSTALL_PATH = "/usr/local/lib";  
  23.             DYLIB_INSTALL_NAME_BASE = "$(INSTALL_PATH)";  
  24.             LD_DYLIB_INSTALL_NAME = "$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)";  
  25.             DYLIB_COMPATIBILITY_VERSION = "1";  
  26.             DYLIB_CURRENT_VERSION = "1";  
  27.             FRAMEWORK_FLAG_PREFIX = "-framework";  
  28.             LIBRARY_FLAG_PREFIX = "-l";  
  29.             LIBRARY_FLAG_NOSPACE = YES;  
  30.             STRIP_STYLE = "debugging";  
  31.             GCC_INLINES_ARE_PRIVATE_EXTERN = YES;  
  32.             CODE_SIGNING_ALLOWED = NO;  
  33.         };  
  34.         PackageTypes = (  
  35.             com.apple.package-type.mach-o-library   // default  
  36.         );  
  37.     },  
  38.  
  39. 在iPhoneOSPackageTypes.xcspec中添加下列片段  
  40.  
  41. // Mach-O dynamic library  
  42.     {   Type = PackageType;  
  43.         Identifier = com.apple.package-type.mach-o-library;  
  44.         Name = "Mach-O Dynamic Library";  
  45.         Description = "Mach-O dynamic library";  
  46.         DefaultBuildSettings = {  
  47.             EXECUTABLE_PREFIX = "";  
  48.             EXECUTABLE_SUFFIX = ".dylib";  
  49.             EXECUTABLE_NAME = "$(EXECUTABLE_PREFIX)$(PRODUCT_NAME)$(EXECUTABLE_VARIANT_SUFFIX)$(EXECUTABLE_SUFFIX)";  
  50.             EXECUTABLE_PATH = "$(EXECUTABLE_NAME)";  
  51.         };  
  52.         ProductReference = {  
  53.             FileType = compiled.mach-o.dylib;  
  54.             Name = "$(EXECUTABLE_NAME)";  
  55.             IsLaunchable = NO;  
  56.         };  
  57.     }, 

文件附上,可以直接下載替換,替換/修改前做好備份

[attachment=10546]

現(xiàn)在再編譯應(yīng)該不會(huì)提示工程不支持了,那么剩下的就是改變其編譯選項(xiàng)了,就是libtool的參數(shù)問(wèn)題。

我們需要修改下列文件

  1. /Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/Libtool.xcspec  
  2. /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Plug-ins/iPhoneOS Build System Support.
  3. xcplugin/Contents/Resources/iPhoneLinkerOptions.xcspec  
  4. 在Libtool.xcspec中添加下列片段  
  5.  
  6. {   Identifier = com.apple.pbx.linkers.libtooldynamic;  
  7.     Type = Linker;  
  8.     Class = PBXLinkerSpecificationLibtool;  
  9.     Name = "Libtool";  
  10.     Description = "Create a dynamic library using Apple Mach-O Librarian (libtool)";  
  11.     IsAbstract = Yes;       // This is an internal tool, so we keep it out of the user interface  
  12.     BinaryFormats = (mach-o);  
  13.     Architectures = (ppc, ppc7400, ppc7450, ppc970, ppc64, i386, x86_64);  
  14.     CommandLine = "$(LIBTOOL) -dynamic -arch_only $(arch) -compatibility_version $(DYLIB_COMPATIBILITY_VERSION) 
  15. -current_version $(DYLIB_CURRENT_VERSION) [options] [special-args] -o $(OutputPath)";     
  16.  // 'special-args' includes the input files  
  17.     RuleName = "Libtool $(OutputPath) $(variant) $(arch)";  
  18.     ExecDescription = "Create Dynamic Library $(OutputPath:file)";  
  19.     InputFileTypes = (  
  20.         compiled.mach-o.objfile  
  21.     );  
  22.     Outputs = (  
  23.         // We're a linker-like task, so we expect to be given an output path in 'OutputPath'.  
  24.         "$(OutputPath)"  
  25.     );  
  26.     CommandOutputParser = XCGccCommandOutputParser;  
  27.     Options = (  
  28.         // LIBTOOL  
  29.         {   Name = LIBTOOL;  
  30.             Type = Path;  
  31.             DefaultValue = "$(PLATFORM_DEVELOPER_BIN_DIR)/libtool";  
  32.         },  
  33.  
  34.         // SDK  
  35.         {   Name = SDKROOT;  
  36.             Type = Path;  
  37.             CommandLineFlag = "-syslibroot";  
  38.             IsInputDependency = Yes;  
  39.         },  
  40.  
  41.         // Search paths  
  42.         {   Name = LIBRARY_SEARCH_PATHS;  
  43.             Type = PathList;  
  44.             FlattenRecursiveSearchPathsInValue = Yes;   // causes any paths that have a '/**' suffix to be replaced with matching paths  
  45.             CommandLinePrefixFlag = "-L";  
  46.         },  
  47.  
  48.         // Input file lists  
  49.         {   Name = __INPUT_FILE_LIST_PATH__;  
  50.             Type = Path;  
  51.             DefaultValue = "$(LINK_FILE_LIST_$(variant)_$(arch))";      // this is set up for us as a read-only property  
  52.             CommandLineFlag = "-filelist";  
  53.             IsInputDependency = Yes;  
  54.         },  
  55.         {   Name = auxiliary_file_lists;  
  56.             Type = PathList;  
  57.             CommandLineFlag = "-filelist";  
  58.             IsInputDependency = Yes;  
  59.         },  
  60.  
  61.         // Various flags  
  62.         {   Name = ALL_OTHER_LIBTOOLFLAGS;  
  63.             Type = StringList;  
  64.             DefaultValue = "$(LD_FLAGS) $(SECTORDER_FLAGS) $(OTHER_LDFLAGS) $(OTHER_LDFLAGS_$(variant))
  65.   $(OTHER_LDFLAGS_$(arch)) $(OTHER_LDFLAGS_$(variant)_$(arch)) $(OTHER_LIBTOOLFLAGS) $(OTHER_LIBTOOLFLAGS_$(variant)) 
  66. $(OTHER_LIBTOOLFLAGS_$(arch)) $(OTHER_LIBTOOLFLAGS_$(variant)_$(arch)) $(PRODUCT_SPECIFIC_LIBTOOLFLAGS)";  
  67.             CommandLinePrefixFlag = "";  
  68.         },  
  69.         {   Name = EXPORTED_SYMBOLS_FILE;  
  70.             Type = Path;  
  71.             Condition = "$(SEPARATE_SYMBOL_EDIT) == NO";  
  72.             CommandLineFlag = "-exported_symbols_list";  
  73.             IsInputDependency = Yes;  
  74.         },  
  75.         {   Name = UNEXPORTED_SYMBOLS_FILE;  
  76.             Type = Path;  
  77.             Condition = "$(SEPARATE_SYMBOL_EDIT) == NO";  
  78.             CommandLineFlag = "-unexported_symbols_list";  
  79.             IsInputDependency = Yes;  
  80.         },  
  81.         {   Name = AdditionalCommandLineArguments;  
  82.             Type = StringList;  
  83.             CommandLinePrefixFlag = "";  
  84.         },  
  85.  
  86.         {   Name = MACOSX_DEPLOYMENT_TARGET;  
  87.             Type = String;  
  88.             SetValueInEnvironmentVariable = "MACOSX_DEPLOYMENT_TARGET";  
  89.         },  
  90.     );  
  91. }, 

在iPhoneLinkerOptions.xcspec中搜索

  1. BasedOn = "default:com.apple.pbx.linkers.libtool"

替換成

  1. BasedOn = "default:com.apple.pbx.linkers.libtooldynamic"

這樣修改后編譯iphone的library工程師都會(huì)使用dynamic的參數(shù)來(lái)編譯,

注意:如果要編譯iphone static library這里需要將libtooldynamic修改回libtool并重啟Xcode(***的小缺陷,應(yīng)該可以通過(guò)hook xcode編譯設(shè)置函數(shù)來(lái)動(dòng)態(tài)修改,很麻煩,需要很多時(shí)間去找到相應(yīng)的方法,找了一會(huì)兒就沒(méi)高興繼續(xù),先將就用吧)

做好以上工作后就可以創(chuàng)建并編譯iphone上dynamic library的工程了。

這里附上工程和target模板文件

  1. [attachment=10547

解壓此zip得到Cocoa Touch Dynamic Library文件夾,將其放到

  1. /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Library/下面  
  2. [attachment=10548

解壓此zip得到Dynamic Library.trgttmpl文件,將其放到

  1. /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Target Templates/Cocoa Touch/下面 

重啟Xcode就可以看到了,如圖

  1. [attachment=10549]  [attachment=10550]  

測(cè)試結(jié)果

  1. [attachment=10551]  

使用otool查看編譯出來(lái)的dylib文件

  1. [attachment=10552]  

成功!

謹(jǐn)記?。。。?!需要修改文件來(lái)切換回編譯static library?。?!

小結(jié):關(guān)于修改Xcode配置并支持iPhonedylib工程的內(nèi)容介紹完了,希望本文對(duì)你有所幫助,更多相關(guān)內(nèi)容請(qǐng)參考便捷而推薦。

責(zé)任編輯:zhaolei 來(lái)源: 博客園
相關(guān)推薦

2011-07-27 14:56:07

iPhone Makefile Dylib

2011-08-08 17:31:30

Xcode 工程

2011-08-04 17:24:12

iPhone開(kāi)發(fā) Xcode 窗口

2011-07-06 18:10:20

Xcode 4 iPhone

2011-07-06 15:44:26

iPhone XCode Leopard

2011-07-07 15:32:07

2011-07-06 17:53:40

iPhone SDK Xcode

2011-07-07 09:20:30

Xcode

2023-02-08 18:08:16

2011-07-06 18:31:21

Xcode 4 iPhone 模擬器

2011-07-07 17:36:13

iPhone Xcode 窗口

2011-07-20 10:12:33

XCode Cocoa dylib

2011-07-22 18:25:20

XCode iPhone SDK

2011-08-04 17:19:49

iPhone開(kāi)發(fā) Xcode 文檔

2011-07-06 17:48:30

iPhone Xcode 模擬器

2019-04-22 11:50:38

LinuxFlatpak

2011-07-20 10:59:46

2011-07-18 17:52:47

Linux iPhone

2011-07-25 18:02:51

iPhone LibFetion 移植

2011-07-06 10:32:07

Xcode
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)