All about linking libraries - How to solve import/link errors- - Anatomy of linking libraries or frameworks - Anatomy: importing libraries or frameworks
All about linkinglibrariesHow to solve import/link errors
View Slide
How do you use libraries orframeworks in Swift project?
Dragging to Embedded Binaries
Import frameworks without modules(Some ObjC vendored frameworks)
Dynamic vs Staticw/ Bundle vs wo/BundleStatic Library (*.a)Static Framework (*.framework)Dynamic Framework (*.framework)Dynamic Library (*.dylib)
with Bundle without BundleStatic LinkingDynamic LinkingDynamic vs Staticw/ Bundle vs wo/BundleStatic LibraryStatic FrameworkDynamic LibraryDynamic Framework
Anatomy of linking libraries orframeworks
How to make availableexternal frameworks/libraries in Swift• Import the framework/library from your app or framework• Link the framework/library to your app or framework
How Swift importframeworks/libraries
What need to import libraries into Swift?
Module
Frameworks can contain modules
Some frameworks don't have modules
Any Library doesn't have modulesStatic Library (*.a)Dynamic Library (*.dylib)
Anatomy: importinglibraries or frameworks
How to import frameworks• Does the framework has modules?Yes:=> Set parent directory of the framework to Framework Search Paths
Set parent directory of the framework toFramework Search Paths
How to import frameworks• Does the framework has modules?No:• Do you try to import the framework to your app?Yes:=> a) Create module map. b) Create bridging header.No:=> Create module map.
a) Bridging Header
a.) Bridging Header
b) Module Map
b) Module Mapmodule Marketo {umbrella header "../../Frameworks/Marketo.framework/Headers/Marketo.h"export *module * { export * }}
b.) Module Map
Import libraries
How to import libraries• a) Create bridging header.• b) Create module map.
b) Module Mapmodule WebPDecoder {header "include/decode.h"header "include/types.h"}
Anatomy: linkinglibraries or frameworks
How to link frameworks• Is the framework dynamic framework?Yes:=> Copy the framework into the app bundle=> Set parent directory of the framework to Framework Search Paths=> Set -framework to Other Linker FlagsNo:=> Set parent directory of the framework to Framework Search Paths=> Set -framework to Other Linker Flagse.g.) -framework KeychainAccess
Link dynamic frameworks
Copy frameworks into app bundles
Link frameworks
How to link libraries• Is the library dynamic library?Yes:=> Set parent directory of the framework to Library Search Paths=> Copy the library into the app bundleNo:=> Set parent directory of the framework to Library Search Paths=> Set -l to Other Linker Flagse.g.) -lwebpdecoder
Link libraries
You might see...=> Correct module map=> Make sure Header Search Paths is correct
Recap• The processes of making external libraries available in the Swift project.=> Import and Linking• Errors on importing=> Module maps, Framework/Library Search Paths, Import Paths• Errors on linking => Module maps, Framework/Library Search Paths, Static or Dynamic• Errors on runtime=> "Copy Files" Build phase
Resources• http://nsomar.com/modular-framework-creating-and-using-them/• https://theswiftdev.com/2018/01/25/deep-dive-into-swift-frameworks/• https://samsymons.com/blog/understanding-objective-c-modules/• http://clang.llvm.org/docs/Modules.html