Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

Kishikawa Katsumi

March 22, 2019
Tweet

More Decks by Kishikawa Katsumi

Other Decks in Technology

Transcript

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

    View Slide

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

    View Slide

  3. Dragging to Embedded Binaries

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  7. Anatomy of linking libraries or
    frameworks

    View Slide

  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

    View Slide

  9. How Swift import
    frameworks/libraries

    View Slide

  10. What need to import libraries into Swift?

    View Slide

  11. Module

    View Slide

  12. Frameworks can contain modules

    View Slide

  13. Some frameworks don't have modules

    View Slide

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

    View Slide

  15. Anatomy: importing
    libraries or frameworks

    View Slide

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

    Yes:

    => Set parent directory of the framework to Framework Search Paths

    View Slide

  17. Set parent directory of the framework to
    Framework Search Paths

    View Slide

  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.

    View Slide

  19. a) Bridging Header

    View Slide

  20. a) Bridging Header

    View Slide

  21. a.) Bridging Header

    View Slide

  22. b) Module Map

    View Slide

  23. b) Module Map

    View Slide

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

    View Slide

  25. b.) Module Map

    View Slide

  26. Import libraries

    View Slide

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

    • b) Create module map.

    View Slide

  28. Import libraries

    View Slide

  29. a) Bridging Header

    View Slide

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

    View Slide

  31. Anatomy: linking
    libraries or frameworks

    View Slide

  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 to Other Linker Flags

    No:

    => Set parent directory of the framework to Framework Search Paths

    => Set -framework to Other Linker Flags
    e.g.) -framework KeychainAccess

    View Slide

  33. Link dynamic frameworks

    View Slide

  34. Copy frameworks into app bundles

    View Slide

  35. Link frameworks

    View Slide

  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 to Other Linker Flags
    e.g.) -lwebpdecoder

    View Slide

  37. Link libraries

    View Slide

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

    => Make sure Header Search Paths is correct

    View Slide

  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

    View Slide

  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

    View Slide