SlideShare a Scribd company logo
Dynamic Library Encapsulation
Written By: Cole Herzog
Last Updated: 5-Aug-2014
Version: 1.0
Encapsulating Libraries in Frameworks
Overview
This document was created to explain the process behind embedding a Dynamic-Linked Library
(Dylibs) inside of a Framework and is specific to Xcode development. Some of the information is
not specific on Xcode. A framework may be dependent on external DLLs, and as such must be
aware of their location on the host system. This document is targeted at frameworks that are
meant for use on multiple host systems.
Dylibs on Disk
The dylibs must be present on disk originally, but once they are copied into the Xcode
framework project they can be removed assuming everything was done correctly.
The dylibs can be installed through whichever means is most convenient. Brew is highly
recommended, though entirely optional. Once the dylibs are installed, locate them on disk and
retain the location.
Embedding Dylibs into the Framework
The majority of the work will be done in Xcode's Target Configuration and build settings
Windows.
With the Framework as the target:
1. Click on Build Phases
2. In the Top left area of the build phases tab hit the + button
Add a New Copy Files Phase
3. Drag and drop the dylibs into the newly created phase, or use the + button within the
phase and navigate to the dylibs
The Destination and Subpath options dictate the location of the library
Wrapper is the recommended destination
../$(VERSIONS_FOLDER_PATH)/$(FRAMEWORK_VERSION)/Library is the
recommended Subpath.
These are environment variables supplied by Xcode and can be found here
This will create a Folder called Library in
yourFrame.framework/Versions/Current
Current is a symlink likely pointing to A depending on the
framework
Note: You may place the dylibs wherever you would like inside of the framework, as long
as you can locate them using the Xcode environment variables. These variables allow the
framework to locate the libraries no matter what the current host system's file heirarchy
is.
Helping the Framework locate the Dylibs
While the Dylibs have now been added to the framework's file heirarchy, the unix executable
portion of the framework will not bother looking there unless explicitly told to. Achieving this
requires an understand of @rpath , @executable_path , possibly @loader_path , otool,
install_name_tool, and writing scripts.
@executable_path
executable_path is the most basic of the three paths. This is simply the location of the folder
MacOS within the calling application.
Example: yourApp.app/Contents/MacOS
@loader_path
loader_path is very close to executable_path, and in the overwhelming majority of cases points
to the exact same folder. The difference is @loader_path will point to the location of whatever
loaded the framework. This is useful in the case of an application requiring a framework, and
then said framework requiring another framework. The app's embedded framework would
reference its embedded framework through @loader_path, as @executable_path will always
point to the Application itself.
Note: This was added in 10.4
@rpath
rpath is the most recently added, and most useful of the three path variables. rpath can be
described as a localized PATH variable. In Xcode the contents of @rpath can be found under the
Build Settings for the framework Target and is called Runpath Search Paths .
Example: If /tmp/ , /Libraries/Frameworks , and /etc/ were added to @rpath the
@rpath/myDir would expand into /tmp/myDir , /Libraries/Frameworks/myDir , and
/etc/myDir .
Note: This was added in 10.5
otool -L
Running the command otool -L on a unix executable will list all of the dependent libraries for
the executable as well as where the executable has been instructed to search for them. Altering
this list is how a framework can be told to search itself for its dependent libraries.
Example: otool -L
/Library/Frameworks/iTunesLibrary.framework/Versions/A/iTunesLibrary
install_name_tool
This command line tool is used to modify the list that otool -L gives. The syntax for changing
one of the entries is
install_name_tool -change old new target
Old refers to the path currently listed for the executable.
New refers to the path that will replace the listed Old path.
Target refers to the executable being changed.
Example: install_name_tool -change /usr/local/lib/libssh2.1.dylib
@rpath/$VERSIONS_FOLDER_PATH/$FRAMEWORK_VERSION/Library/libssh2.1.dylib
$BUILT_PRODUCTS_DIR/$VERSIONS_FOLDER_PATH/$FRAMEWORK_VERSION/$PROJECT
Note: The dylibs a framework lists as dependencies may also have dependencies.
install_name_tool must be used on these dylibs as well to explicitly tell them where to
search for the other dylibs they themselves are dependent on.
Scripts
Unfortunately, even though an executable has been delicately changed using install_name_tool,
every time the folder is cleaned and the framework is built a new executable will be created
without the necessary changes. To fix this Xcode can be told to run a script after building.
In the Top left area of the build phases tab hit the + button
Add a New Run Script Phase [This should be the final build phase]
In the text field type or copy + paste the script [The code, not the file]
All required install_name_tool scripts should be here, as shown in the
above example. As every situation is different this script must be created
specifically for each framework. @rpath should likely be the beginning of
the New argument for install_name_tool, and a path to the framework's
executable should be created using Xcode's environment variables for the
Target argument.
Note: The framework's dependent libraries must also have their dependencies changed in
this script as referenced in the note above.
Helping the Dylibs locate their Dylibs
As the most recent notes have mentioned, dylibs the framework is dependent on may have
dependencies themselves (sub dependencies). These sub dependencies must be included in
the project, and their dylibs must be altered using install_name_tool (likely with the help of otool
-L). These install_name_tool commands should be added to the framework's script.
Build Settings
Under the build settings tab for the framework the Skip Install option should be set to Yes .
The framework is not being installed anywhere, as it will be embedded itself within the calling
application. All required linker flags under the Other Linker Flags option must be set for any
added dylibs (check specific dylib’s documentation for more information).
Example: -lssh2
Embedding Frameworks into applications
While the work on the individual framework has been completed, the framework now has to be
encapsulated within the application, and the application has to be told where to look for its
frameworks.
1. Go to the application's Build Phases tab
2. In the Top left area of the build phases tab hit the + button
Add a New Copy Files Phase
Change the Destination to Frameworks
Copy only when installing should be unchecked
Either add of drag and drop the framework into the build phase
Note: This automatically copies the framework into
@executable_path/../Frameworks@executable_path/../Frameworks
Helping the application locate the frameworks
The framework has been added to the application in the correct location, but the application has
not been instructed to search for said framework.
1. Go to the application's Build Settings tab
2. The Runpath Search Paths setting (@rpath) needs to include
@executable_path/../Frameworks
If this is a framework calling another framework,
@loader_path/../Frameworks should be used instead
3. The Frameworks Search Paths setting needs to include
$(TARGET_BUILD_DIR)/$(FRAMEWORKS_FOLDER_PATH)
These bash variables point to the yourApp.app/Contents/Frameworks
directory
Finishing
The product should now have:
1. embedded dylibs in the framework
2. dylibs that know the location of their individual dependencies
3. a Framework that knows where to look for its dependent libraries
4. an Application with an embedded framework
5. an Application that knows where to find its dependent frameworks
Note: The application should now be a completely standalone application. If it is not, a
mistake was made. The best way to test this is to either delete or alter the names of all
required dylibs and frameworks on disk.

More Related Content

What's hot

web programming Unit VI PPT by Bhavsingh Maloth
web programming Unit VI PPT  by Bhavsingh Malothweb programming Unit VI PPT  by Bhavsingh Maloth
web programming Unit VI PPT by Bhavsingh Maloth
Bhavsingh Maloth
 
Savitch Ch 06
Savitch Ch 06Savitch Ch 06
Savitch Ch 06
Terry Yoast
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
Bhavsingh Maloth
 
R12 d49656 gc10-apps dba 24
R12 d49656 gc10-apps dba 24R12 d49656 gc10-apps dba 24
R12 d49656 gc10-apps dba 24
zeesniper
 
intro unix/linux 08
intro unix/linux 08intro unix/linux 08
intro unix/linux 08
duquoi
 
Unit 1-introduction to perl
Unit 1-introduction to perlUnit 1-introduction to perl
Unit 1-introduction to perl
sana mateen
 
Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6
Shahrzad Peyman
 
Using SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint developmentUsing SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint development
Pranav Sharma
 
Basic Make
Basic MakeBasic Make
Basic Make
Alec Clews
 
Automating API Documentation
Automating API DocumentationAutomating API Documentation
Automating API Documentation
Selvakumar T S
 
Copy verb in cobol
Copy verb in cobolCopy verb in cobol
Copy verb in cobol
RammurthyT
 
Using SP Metal for faster share point development
Using SP Metal for faster share point developmentUsing SP Metal for faster share point development
Using SP Metal for faster share point developmentPranav Sharma
 
Data pump-export-examples
Data pump-export-examplesData pump-export-examples
Data pump-export-examples
raima sen
 
R12 d49656 gc10-apps dba 10
R12 d49656 gc10-apps dba 10R12 d49656 gc10-apps dba 10
R12 d49656 gc10-apps dba 10
zeesniper
 
microsoft help
microsoft helpmicrosoft help
microsoft help
hambali_nurmi
 
07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development
rehaniltifat
 

What's hot (19)

web programming Unit VI PPT by Bhavsingh Maloth
web programming Unit VI PPT  by Bhavsingh Malothweb programming Unit VI PPT  by Bhavsingh Maloth
web programming Unit VI PPT by Bhavsingh Maloth
 
Savitch Ch 06
Savitch Ch 06Savitch Ch 06
Savitch Ch 06
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
 
Savitch ch 06
Savitch ch 06Savitch ch 06
Savitch ch 06
 
R12 d49656 gc10-apps dba 24
R12 d49656 gc10-apps dba 24R12 d49656 gc10-apps dba 24
R12 d49656 gc10-apps dba 24
 
Ant tutorial
Ant tutorialAnt tutorial
Ant tutorial
 
intro unix/linux 08
intro unix/linux 08intro unix/linux 08
intro unix/linux 08
 
Unit 1-introduction to perl
Unit 1-introduction to perlUnit 1-introduction to perl
Unit 1-introduction to perl
 
ANSI C Macros
ANSI C MacrosANSI C Macros
ANSI C Macros
 
Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6
 
Using SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint developmentUsing SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint development
 
Basic Make
Basic MakeBasic Make
Basic Make
 
Automating API Documentation
Automating API DocumentationAutomating API Documentation
Automating API Documentation
 
Copy verb in cobol
Copy verb in cobolCopy verb in cobol
Copy verb in cobol
 
Using SP Metal for faster share point development
Using SP Metal for faster share point developmentUsing SP Metal for faster share point development
Using SP Metal for faster share point development
 
Data pump-export-examples
Data pump-export-examplesData pump-export-examples
Data pump-export-examples
 
R12 d49656 gc10-apps dba 10
R12 d49656 gc10-apps dba 10R12 d49656 gc10-apps dba 10
R12 d49656 gc10-apps dba 10
 
microsoft help
microsoft helpmicrosoft help
microsoft help
 
07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development
 

Viewers also liked

Gillermo
GillermoGillermo
Gillermoaula
 
Plaquette taxe apprentissage ESN 2014
Plaquette taxe apprentissage ESN 2014Plaquette taxe apprentissage ESN 2014
Plaquette taxe apprentissage ESN 2014
Ensemble Scolaire Niortais
 
International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)
inventionjournals
 
DEPRESSÕES NO CRETÁCICO DE SANTO AMARO DE OEIRAS – PEGADAS OU NÃO?
DEPRESSÕES  NO CRETÁCICO DE SANTO AMARO DE OEIRAS – PEGADAS OU NÃO?DEPRESSÕES  NO CRETÁCICO DE SANTO AMARO DE OEIRAS – PEGADAS OU NÃO?
DEPRESSÕES NO CRETÁCICO DE SANTO AMARO DE OEIRAS – PEGADAS OU NÃO?
Celestino Coutinho
 

Viewers also liked (6)

The life you want
The life you wantThe life you want
The life you want
 
Gillermo
GillermoGillermo
Gillermo
 
Plaquette taxe apprentissage ESN 2014
Plaquette taxe apprentissage ESN 2014Plaquette taxe apprentissage ESN 2014
Plaquette taxe apprentissage ESN 2014
 
International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)
 
DEPRESSÕES NO CRETÁCICO DE SANTO AMARO DE OEIRAS – PEGADAS OU NÃO?
DEPRESSÕES  NO CRETÁCICO DE SANTO AMARO DE OEIRAS – PEGADAS OU NÃO?DEPRESSÕES  NO CRETÁCICO DE SANTO AMARO DE OEIRAS – PEGADAS OU NÃO?
DEPRESSÕES NO CRETÁCICO DE SANTO AMARO DE OEIRAS – PEGADAS OU NÃO?
 
9782703307921
97827033079219782703307921
9782703307921
 

Similar to dylibencapsulation

Why Drupal is Rockstar?
Why Drupal is Rockstar?Why Drupal is Rockstar?
Why Drupal is Rockstar?
Gerald Villorente
 
Drupal - Introduction to Drupal Creating Modules
Drupal - Introduction to Drupal Creating ModulesDrupal - Introduction to Drupal Creating Modules
Drupal - Introduction to Drupal Creating Modules
Vibrant Technologies & Computers
 
Getting started-with-zend-framework
Getting started-with-zend-frameworkGetting started-with-zend-framework
Getting started-with-zend-frameworkNilesh Bangar
 
Getting started-with-zend-framework
Getting started-with-zend-frameworkGetting started-with-zend-framework
Getting started-with-zend-frameworkMarcelo da Rocha
 
Exploit Frameworks
Exploit FrameworksExploit Frameworks
Exploit Frameworksphanleson
 
Android coding guide lines
Android coding guide linesAndroid coding guide lines
Android coding guide lineslokeshG38
 
Laravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php frameworkLaravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php framework
Swapnil Tripathi ( Looking for new challenges )
 
Intro to drupal module internals asheville
Intro to drupal module internals ashevilleIntro to drupal module internals asheville
Intro to drupal module internals asheville
cgmonroe
 
Gigigo Workshop - Create an iOS Framework, document it and not die trying
Gigigo Workshop - Create an iOS Framework, document it and not die tryingGigigo Workshop - Create an iOS Framework, document it and not die trying
Gigigo Workshop - Create an iOS Framework, document it and not die trying
Alex Rupérez
 
Drupal
DrupalDrupal
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptx
SaziaRahman
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010Rich Helton
 
1 of 9 CSCE 3600 Systems Programming Major Assignm.docx
  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx
1 of 9 CSCE 3600 Systems Programming Major Assignm.docx
ShiraPrater50
 
Drupal 8 meets to symphony
Drupal 8 meets to symphonyDrupal 8 meets to symphony
Drupal 8 meets to symphony
Brahampal Singh
 
App dba hints
App dba hintsApp dba hints
App dba hints
ramaappsdba10
 
Digital Fabrication Studio v.0.2: Information
Digital Fabrication Studio v.0.2: InformationDigital Fabrication Studio v.0.2: Information
Digital Fabrication Studio v.0.2: Information
Massimo Menichinelli
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
Jonathan Goode
 
Composer namespacing
Composer namespacingComposer namespacing
Composer namespacing
Deepak Chandani
 
13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview
13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview
13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview
DrupalMumbai
 

Similar to dylibencapsulation (20)

Why Drupal is Rockstar?
Why Drupal is Rockstar?Why Drupal is Rockstar?
Why Drupal is Rockstar?
 
Drupal - Introduction to Drupal Creating Modules
Drupal - Introduction to Drupal Creating ModulesDrupal - Introduction to Drupal Creating Modules
Drupal - Introduction to Drupal Creating Modules
 
Getting started-with-zend-framework
Getting started-with-zend-frameworkGetting started-with-zend-framework
Getting started-with-zend-framework
 
Getting started-with-zend-framework
Getting started-with-zend-frameworkGetting started-with-zend-framework
Getting started-with-zend-framework
 
Exploit Frameworks
Exploit FrameworksExploit Frameworks
Exploit Frameworks
 
Android coding guide lines
Android coding guide linesAndroid coding guide lines
Android coding guide lines
 
Laravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php frameworkLaravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php framework
 
Intro to drupal module internals asheville
Intro to drupal module internals ashevilleIntro to drupal module internals asheville
Intro to drupal module internals asheville
 
Gigigo Workshop - Create an iOS Framework, document it and not die trying
Gigigo Workshop - Create an iOS Framework, document it and not die tryingGigigo Workshop - Create an iOS Framework, document it and not die trying
Gigigo Workshop - Create an iOS Framework, document it and not die trying
 
Drupal
DrupalDrupal
Drupal
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptx
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
 
1 of 9 CSCE 3600 Systems Programming Major Assignm.docx
  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx  1 of 9 CSCE 3600 Systems Programming  Major Assignm.docx
1 of 9 CSCE 3600 Systems Programming Major Assignm.docx
 
Drupal 8 meets to symphony
Drupal 8 meets to symphonyDrupal 8 meets to symphony
Drupal 8 meets to symphony
 
App dba hints
App dba hintsApp dba hints
App dba hints
 
Technical Interview
Technical InterviewTechnical Interview
Technical Interview
 
Digital Fabrication Studio v.0.2: Information
Digital Fabrication Studio v.0.2: InformationDigital Fabrication Studio v.0.2: Information
Digital Fabrication Studio v.0.2: Information
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
 
Composer namespacing
Composer namespacingComposer namespacing
Composer namespacing
 
13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview
13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview
13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview
 

dylibencapsulation

  • 1. Dynamic Library Encapsulation Written By: Cole Herzog Last Updated: 5-Aug-2014 Version: 1.0 Encapsulating Libraries in Frameworks Overview This document was created to explain the process behind embedding a Dynamic-Linked Library (Dylibs) inside of a Framework and is specific to Xcode development. Some of the information is not specific on Xcode. A framework may be dependent on external DLLs, and as such must be aware of their location on the host system. This document is targeted at frameworks that are meant for use on multiple host systems. Dylibs on Disk The dylibs must be present on disk originally, but once they are copied into the Xcode framework project they can be removed assuming everything was done correctly. The dylibs can be installed through whichever means is most convenient. Brew is highly recommended, though entirely optional. Once the dylibs are installed, locate them on disk and retain the location. Embedding Dylibs into the Framework The majority of the work will be done in Xcode's Target Configuration and build settings Windows. With the Framework as the target: 1. Click on Build Phases 2. In the Top left area of the build phases tab hit the + button Add a New Copy Files Phase 3. Drag and drop the dylibs into the newly created phase, or use the + button within the phase and navigate to the dylibs The Destination and Subpath options dictate the location of the library Wrapper is the recommended destination ../$(VERSIONS_FOLDER_PATH)/$(FRAMEWORK_VERSION)/Library is the recommended Subpath. These are environment variables supplied by Xcode and can be found here This will create a Folder called Library in
  • 2. yourFrame.framework/Versions/Current Current is a symlink likely pointing to A depending on the framework Note: You may place the dylibs wherever you would like inside of the framework, as long as you can locate them using the Xcode environment variables. These variables allow the framework to locate the libraries no matter what the current host system's file heirarchy is. Helping the Framework locate the Dylibs While the Dylibs have now been added to the framework's file heirarchy, the unix executable portion of the framework will not bother looking there unless explicitly told to. Achieving this requires an understand of @rpath , @executable_path , possibly @loader_path , otool, install_name_tool, and writing scripts. @executable_path executable_path is the most basic of the three paths. This is simply the location of the folder MacOS within the calling application. Example: yourApp.app/Contents/MacOS @loader_path loader_path is very close to executable_path, and in the overwhelming majority of cases points to the exact same folder. The difference is @loader_path will point to the location of whatever loaded the framework. This is useful in the case of an application requiring a framework, and then said framework requiring another framework. The app's embedded framework would reference its embedded framework through @loader_path, as @executable_path will always point to the Application itself. Note: This was added in 10.4 @rpath rpath is the most recently added, and most useful of the three path variables. rpath can be described as a localized PATH variable. In Xcode the contents of @rpath can be found under the Build Settings for the framework Target and is called Runpath Search Paths . Example: If /tmp/ , /Libraries/Frameworks , and /etc/ were added to @rpath the @rpath/myDir would expand into /tmp/myDir , /Libraries/Frameworks/myDir , and /etc/myDir . Note: This was added in 10.5
  • 3. otool -L Running the command otool -L on a unix executable will list all of the dependent libraries for the executable as well as where the executable has been instructed to search for them. Altering this list is how a framework can be told to search itself for its dependent libraries. Example: otool -L /Library/Frameworks/iTunesLibrary.framework/Versions/A/iTunesLibrary install_name_tool This command line tool is used to modify the list that otool -L gives. The syntax for changing one of the entries is install_name_tool -change old new target Old refers to the path currently listed for the executable. New refers to the path that will replace the listed Old path. Target refers to the executable being changed. Example: install_name_tool -change /usr/local/lib/libssh2.1.dylib @rpath/$VERSIONS_FOLDER_PATH/$FRAMEWORK_VERSION/Library/libssh2.1.dylib $BUILT_PRODUCTS_DIR/$VERSIONS_FOLDER_PATH/$FRAMEWORK_VERSION/$PROJECT Note: The dylibs a framework lists as dependencies may also have dependencies. install_name_tool must be used on these dylibs as well to explicitly tell them where to search for the other dylibs they themselves are dependent on. Scripts Unfortunately, even though an executable has been delicately changed using install_name_tool, every time the folder is cleaned and the framework is built a new executable will be created without the necessary changes. To fix this Xcode can be told to run a script after building. In the Top left area of the build phases tab hit the + button Add a New Run Script Phase [This should be the final build phase] In the text field type or copy + paste the script [The code, not the file] All required install_name_tool scripts should be here, as shown in the above example. As every situation is different this script must be created specifically for each framework. @rpath should likely be the beginning of the New argument for install_name_tool, and a path to the framework's executable should be created using Xcode's environment variables for the Target argument.
  • 4. Note: The framework's dependent libraries must also have their dependencies changed in this script as referenced in the note above. Helping the Dylibs locate their Dylibs As the most recent notes have mentioned, dylibs the framework is dependent on may have dependencies themselves (sub dependencies). These sub dependencies must be included in the project, and their dylibs must be altered using install_name_tool (likely with the help of otool -L). These install_name_tool commands should be added to the framework's script. Build Settings Under the build settings tab for the framework the Skip Install option should be set to Yes . The framework is not being installed anywhere, as it will be embedded itself within the calling application. All required linker flags under the Other Linker Flags option must be set for any added dylibs (check specific dylib’s documentation for more information). Example: -lssh2 Embedding Frameworks into applications While the work on the individual framework has been completed, the framework now has to be encapsulated within the application, and the application has to be told where to look for its frameworks. 1. Go to the application's Build Phases tab 2. In the Top left area of the build phases tab hit the + button Add a New Copy Files Phase Change the Destination to Frameworks Copy only when installing should be unchecked Either add of drag and drop the framework into the build phase Note: This automatically copies the framework into @executable_path/../Frameworks@executable_path/../Frameworks Helping the application locate the frameworks The framework has been added to the application in the correct location, but the application has not been instructed to search for said framework. 1. Go to the application's Build Settings tab 2. The Runpath Search Paths setting (@rpath) needs to include @executable_path/../Frameworks If this is a framework calling another framework,
  • 5. @loader_path/../Frameworks should be used instead 3. The Frameworks Search Paths setting needs to include $(TARGET_BUILD_DIR)/$(FRAMEWORKS_FOLDER_PATH) These bash variables point to the yourApp.app/Contents/Frameworks directory Finishing The product should now have: 1. embedded dylibs in the framework 2. dylibs that know the location of their individual dependencies 3. a Framework that knows where to look for its dependent libraries 4. an Application with an embedded framework 5. an Application that knows where to find its dependent frameworks Note: The application should now be a completely standalone application. If it is not, a mistake was made. The best way to test this is to either delete or alter the names of all required dylibs and frameworks on disk.