All about linking libraries

All about linking libraries

All about linking libraries - How to solve import/link errors-
- Anatomy of linking libraries or frameworks
- Anatomy: importing libraries or frameworks

9bf923e39671cde83584e3e926296c13?s=128

Kishikawa Katsumi

March 22, 2019
Tweet

Transcript

  1. All about linking libraries How to solve import/link errors

  2. How do you use libraries or frameworks in Swift project?

  3. Dragging to Embedded Binaries

  4. Import frameworks without modules (Some ObjC vendored frameworks)

  5. Dynamic vs Static w/ Bundle vs wo/Bundle Static Library (*.a)

    Static Framework (*.framework) Dynamic Framework (*.framework) Dynamic Library (*.dylib)
  6. with Bundle without Bundle Static Linking Dynamic Linking Dynamic vs

    Static w/ Bundle vs wo/Bundle Static Library Static Framework Dynamic Library Dynamic Framework
  7. Anatomy of linking libraries or frameworks

  8. How to make available external frameworks/libraries in Swift • Import

    the framework/library from your app or framework • Link the framework/library to your app or framework
  9. How Swift import frameworks/libraries

  10. What need to import libraries into Swift?

  11. Module

  12. Frameworks can contain modules

  13. Some frameworks don't have modules

  14. Any Library doesn't have modules Static Library (*.a) Dynamic Library

    (*.dylib)
  15. Anatomy: importing libraries or frameworks

  16. How to import frameworks • Does the framework has modules?

    Yes: => Set parent directory of the framework to Framework Search Paths
  17. Set parent directory of the framework to Framework Search Paths

  18. 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.
  19. a) Bridging Header

  20. a) Bridging Header

  21. a.) Bridging Header

  22. b) Module Map

  23. b) Module Map

  24. b) Module Map module Marketo { umbrella header "../../Frameworks/Marketo.framework/Headers/Marketo.h" export

    * module * { export * } }
  25. b.) Module Map

  26. Import libraries

  27. How to import libraries • a) Create bridging header. •

    b) Create module map.
  28. Import libraries

  29. a) Bridging Header

  30. b) Module Map module WebPDecoder { header "include/decode.h" header "include/types.h"

    }
  31. Anatomy: linking libraries or frameworks

  32. 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 <FRAMEWORK_NAME> to Other Linker Flags No: => Set parent directory of the framework to Framework Search Paths => Set -framework <FRAMEWORK_NAME> to Other Linker Flags e.g.) -framework KeychainAccess
  33. Link dynamic frameworks

  34. Copy frameworks into app bundles

  35. Link frameworks

  36. 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 bundle No: => Set parent directory of the framework to Library Search Paths => Set -l<LIBRARY_NAME> to Other Linker Flags e.g.) -lwebpdecoder
  37. Link libraries

  38. You might see... => Correct module map => Make sure

    Header Search Paths is correct
  39. 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
  40. 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