2010-08-18 117 views
8

我正在編寫一個框架(稱爲Lighthouse.framework),該框架反過來使用來自另一個框架(RegexKit.framework,準確地說)的代碼。我抄RegexKit.framework到我自己的框架,因此,它具有如下所示的結構:我可以在另一個框架中包含框架嗎?

Lighthouse.framework/ 
    Versions/ 
    A/ 
     Frameworks/ 
     RegexKit.framework 
     Lighthouse 

然而,當我嘗試運行使用Lighthouse.framework(我的架構)的應用程序,我得到的以下錯誤:

dyld: Library not loaded: @executable_path/../Frameworks/RegexKit.framework/Versions/A/RegexKit

Referenced from: /Users/mdippery/Developer/Projects/Current/lighthouse/build/Debug/Lighthouse.framework/Versions/A/Lighthouse

Reason: image not found

顯然,加載程序沒有找到RegexKit。

我這裏還有裝載機希望加載路徑,禮貌otool

build/Debug/Lighthouse.framework/Versions/A/Lighthouse: 
    /Users/mdippery/Library/Frameworks/Lighthouse.framework/Versions/A/Lighthouse (compatibility version 1.0.0, current version 1.0.0) 
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 12.0.0) 
    @executable_path/../Frameworks/RegexKit.framework/Versions/A/RegexKit (compatibility version 0.4.0, current version 0.6.0) 
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0) 
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4) 
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0) 
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 476.19.0) 
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 677.26.0) 

我可以在另一個框架的框架?這是做到這一點的正確方法嗎?我該如何解決我的錯誤?

+0

下面是如何在另一個框架中包含框架。 http://stackoverflow.com/a/27638841/1582217它被稱爲傘架。 – 2014-12-24 16:21:09

+0

[如何在iOS sdk中創建Umbrella框架?](http://stackoverflow.com/questions/27484997/how-to-create-an-umbrella-framework-in-ios-sdk) – 2014-12-25 08:00:32

回答

1

我發現了此問題的修復程序。我從sbooth的回答中收集了一些想法,但修復更簡單。我運行了這個腳本:

install_name_tool -change @executable_path/../Frameworks/RegexKit.framework/Versions/A/RegexKit @loader_path/Frameworks/RegexKit.framework/Versions/A/RegexKit "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.framework/Versions/A/${PRODUCT_NAME}" 

作爲運行構建腳本階段。

請注意,對於一般情況,您必須將@executable_path/../更改爲@loader_path/,並且一切正常。

+0

您在哪裏設置了這個構建腳本?在框架產品或總產品? – 2016-01-28 12:00:00

1

是的,你可以。但是,您需要包含的框架來「知道」它在安裝位置時的安裝位置;否則,如您所見,dyld將無法​​在運行時找到它。

如果我正確記得,XCode中的相關設置是「安裝目錄」和「框架安裝名稱」。後者可能對你的使用沒有任何影響,但你需要前者是沿着以下幾點:@executable_path/../Frameworks/Lighthouse.framework/Versions/A/Frameworks/RegexKit.framework/Versions/A/

+0

在構建Lighthouse.framework(用於Lighthouse.framework)時設置安裝目錄?我試了一下,但沒有奏效(雖然也許我做錯了)。 – mipadi 2010-08-19 15:12:06

+0

@mipadi:如果你沒有構建'RegExKit.framework',你將無法做到這一點。爲什麼要將RegExKit包含在其他框架中?沒有這個,你正在做的事情會很好。 – 2010-08-19 16:05:10

+0

如果我的框架的消費者只需要包含我的框架,而不是包含我的框架的依賴關係,那將會很好。 – mipadi 2010-08-19 16:10:15

8

最簡單的方法是使用@rpath。你的配置應該是這樣的:

  1. 集RegExKit.framework的安裝目錄,以@rpath
  2. 集Lighthouse.frameworks的安裝目錄,以@rpath
  3. 集Lighthouse.framework的運行路徑搜索路徑,以@ loader_path /框架
  4. 確保將RegExKit.framework複製到Lighthouse.framework的框架子文件夾中(對此使用自定義構建階段)

最後,任何應用程序鏈接g到Lighthouse.framework應設置運行路徑搜索路徑到@loader_path /../框架

+0

我沒有構建RegexKit.framework(我正在使用預編譯的二進制文件)。我是否仍然可以爲其設置安裝目錄(我沒有看到這樣做的方法)? – mipadi 2010-08-19 15:12:58

+1

您可以使用install_name_tool來實現此目的 - 比如install_name_tool -change @executable_path /../ Frameworks @ rpath/Frameworks – sbooth 2010-08-20 00:37:07

相關問題