How do I weak link frameworks on Xcode 4?
Asked Answered
E

2

34

I need to weak link some framework with my target.
But I can't find how to do it...

If I try to run my project on 3.2 iPad simulator i get the following error:

dyld: Library not loaded: /System/Library/Frameworks/iAd.framework/iAd
Reason : Image not found

Thanks !

Ecotone answered 25/6, 2011 at 21:54 Comment(0)
L
57

Go to your project -> Targets -> Build Phases -> Link Binary with Libraries.

Then change the library you want to weak-link from "Required" to "Optional".

Lonni answered 25/6, 2011 at 21:59 Comment(2)
I have enabled the framework as "optional" and the app runs on the device but I get this message in the console "-[ViewController contollerABC] [ABCDocument withDocumentFilePath:'/var/mobile/Containers/Bundle/Application/DFBD7E29-CD8E-4F3B-AA56-2A9A55F63499/XYZKitDemo.app/Document.pdf' password:'(null)'] failed." . Could you please let me know what the problem is?Jellify
This is broken.Wellread
E
9

This doesn't work now. Please follow the link below: https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html

Select the target you want to modify and reveal its build phases.

Expand the Link Binary With Libraries build phase to view the frameworks currently linked by the target.

If the framework you want to weakly link to is listed in the Link Binary With Libraries build phase, select it, and choose Edit > Delete to remove it.

Now you can tell the linker to use weak linking for that framework.

Select the target, open its Info window, and click Build.

To the Other Linker Flags build setting, add the following command-line option specification, where FRAMEWORK_NAME is the name of the framework you want to weakly link to: -weak_framework FRAMEWORK_NAME

Build your product.

Elope answered 4/2, 2013 at 7:37 Comment(2)
For me, using Xcode 12.3, in December 2020, the accepted answer given by uvesten (change "Required" to "Optional") works and has the same effect as this answer. That is, when I look in the Build Transcript, in the Linking phase, when the popup for FRAMEWORK_NAME was set to "Required", the linker invocation has the argument "-framework FRAMEWORK_NAME", but if FRAMEWORK_NAME was set to "Optional", the argument has instead "-weak_framework FRAMEWORK_NAME". So, if Required vs. Optional was indeed broken in 2013, Apple has apparently fixed it since then.Machellemachete
hi! thank you! i have another question how to exclude libraries for armv7 architectures?Editor

© 2022 - 2024 — McMap. All rights reserved.