Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the libraries linking options in Xcode?

As of Xcode 7, there are some library/framework linking options in Xcode

Go to application Target in project tab

General -> Embedded Binaries
General -> Link Frameworks and Libraries
Build Phases -> Target Dependencies
Build Phases -> Link Binary with Libraries

Here are a few ways I found

  • Using Alamofire shows Embedded Binaries option

The Alamofire.framework is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.

  • Creating your first iOS Framework shows that adding the Library.xcodeproj into workspace, then Build Phases -> Link Binary with Libraries

  • Carthage Tutorial: Getting Started shows that dragging Library.framework into General -> Link Frameworks and Libraries. It seems General -> Link Frameworks and Libraries and Build Phases -> Link Binary with Libraries are the same

  • Carthage seems to differentiate between iOS and OS X.

If you're building for OS X: On your application targets’ “General” settings tab, in the “Embedded Binaries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.

If you're building for iOS, tvOS, or watchOS: On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.

Reading Linking to a Library or Framework, we know that these options are about linking a framework into our application/framework.

But what are the differences between them? Is any single option a catch all for all of them?

like image 708
onmyway133 Avatar asked Jan 17 '16 03:01

onmyway133


People also ask

Where is linked frameworks and Libraries in Xcode?

If you're building for iOS, tvOS, or watchOS: On your application targets' “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.

Where is Libraries in Xcode?

At the bottom of the left sidebar, in the “Filter” box, type “Libraries”. If, in the Project Navigator, you now see a yellow folder icon with the word “Libraries” next to it, then you have found the Libraries folder you are looking for.

What are dynamic libraries in Swift?

The type of library that provides this flexibility is called dynamic library. Dynamic libraries are not statically linked into client apps; they don't become part of the executable file. Instead, dynamic libraries can be loaded (and linked) into an app either when the app is launched or as it runs.


1 Answers

For dynamic frameworks built with carthage I usually use this setup:

  • Link the library with any target you want to use it in. You need this to be able to import the framework in your code.
  • Embed the library only in the containing app target. This will actually copy the framework in your app bundle. If you don't embed it your app will crash on startup, because your framework can't be found.

Only the app target is responsible for embedding all the frameworks and their dependencies. That way if an extension and the app both use a framework, it will be distributed with the app only once.

For the Xcode interface:

  • dragging a framework into General -> Embedded Binaries will add the framework to both "Link Binary With Libraries" and "Embed Frameworks" build phases
  • dragging a framework into General -> Linked Frameworks and Libraries will add the framework only to the "Link Binary With Libraries" build phase.

The views under General seem to be filled from the build phases tab so you can use either.

Hope that makes sense.

Edit: Target dependencies are just targets that need to be built before the current target can be built. So your app target would list its extension here, so that the extension gets built, whenever you build your app.

like image 161
Kay Avatar answered Oct 05 '22 22:10

Kay