I'm stuck with including a 3rd party framework (written in Objective-C) into my Swift application. I did the following (which should be sufficient):
Include the framework into the project
Add the framework to the "Link Binary with Libraries" build phase
Add the framework to the "Copy Files" build phase (destination: "Frameworks")
Import the main header of the framework into the bridging header
Compiling the project succeeds. But as soon as I try to run it I receive the following error:
dyld: Library not loaded: /Library/Frameworks/ZipKit.framework/Versions/A/ZipKit
Additionally I set the following settings:
Runpath Search Paths: #executable_path/../Frameworks
Framework Search Paths: #executable_path/../Frameworks (in addition to the source location of the framework)
Library Search Paths: #executable_path/../Frameworks
Nothing seems to work and I don't have any clue why the runtime keeps looking in the /Library folder.
I'm currently using Xcode 6 Beta 6 (as the GM does not support Swift on OS X).
Edit
Just to clarify: The app bundle contains the linked framework after compilation (I've checked that).
Found it.
Fortunately I have the source code of the framework I want to include.
I stumbled upon the install path setting of the framework project which was set to /Library/Frameworks.
I changed this to #executable_path/../Frameworks re-compiled it, re-compiled my project and now it works.
Related
I have an iOS project in XCode 11.2 that requires a mix of Frameworks, some of which are available on Cocoapods and some are not. For the non-Cocoapod frameworks, I have the frameworks copied to the root of my project folder.
The trouble comes with getting XCode to be able to find both using the Framework Search Paths setting as shown here:
All of the entries following $(inherited) are actually the ones inherited from Cocoapods (these are not explicitly specified).
If I don't add the $(PROJECT_DIR) at the end then Cococapod frameworks are found fine, but my embedded non-Cocoapod frameworks get compiler errors that their header files are not found.
If I do add the $(PROJECT_DIR) at the end, then the Cocoapod frameworks are not found and I get a build error like:
ld: warning: directory not found for option '-F/Users/dyoung/Library/Developer/Xcode/DerivedData/MyApp-acdmyjbbrpbhlkfiyypetovwacrz/Build/Products/Debug-iphoneos/AWSAuthCore'
...
ld: framework not found AWSAuthCore
Why? How do I get XCode to find frameworks in both places?
Here's one way:
pod deintegrate
Open the .xcodeproj
Add the non-CocoaPods frameworks.
pod install
Open the .xcworkspace
The problem was that the CocoaPods Frameworks that I was trying to add were built only for iOS 11+, but my very old project had a deployment target of iOS 8.4.
Looking at error details in the Report Navigator as #paul-beusterien suggested was critical. I found this:
Ld /Users/dyoung/Library/Developer/Xcode/DerivedData/MyApp-acdmyjbbrpbhlkfiyypetovwacrz/Build/Intermediates.noindex/MyApp.build/Debug-iphoneos/MyApp.build/Objects-normal/armv7/Binary/MyApp normal armv7 (in target 'MyApp' from project 'MyApp')
The key thing there is the armv7 architecture. This architecture is only part of the build process if you have a deployment target of 10.x or earlier but not if you have 11.x or later. And if the frameworks you are including don't have armv7 architecture (e.g. if they are built for 11.0+), XCode gives very misleading error messages about the frameworks not being found. What really isn't found is that specific architecture inside the framework.
Bottom line: My problem had nothing to do with framework search paths. Removing $(PROJECT_DIR) from the framework search path only appeared to solve the problem by triggering a different compile-time problem to happen before it got to the linker problem.
The solution in this case is that I must change my deployment target to 11.0, then everything builds properly.
I updated one of my core frameworks to use Swift as an experiment. It builds fine, the compatibility header has the Swift classes available to the Objective-C classes that depend on them, and everything compiles fine.
However, when launching the application (base SDK and deployment target OS X 10.10) it crashes immediately with:
dyld: Library not loaded: #rpath/libswift_stdlib_core.dylib
Referenced from: /Users/Craig/Library/Developer/Xcode/DerivedData/MacApp-dxcgahgplwpbjedqnembegifbowj/Build/Products/Debug/Fluffy.framework/Versions/A/Fluffy
Reason: image not found
Note that MacApp is the application I'm launching, and it uses the Fluffy framework containing Swift code.
The Fluffy project has its Runpath Search Paths set to:
#executable_path/Frameworks
But I have also tried it blank. I have tried restarting Xcode, to no avail. Using Yosemite 14A298i and Xcode beta 4.
The Runpath Search Paths for my framework (Fluffy) containing the Swift code needed to be updated. It originally contained:
$(inherited)
#executable_path/../Frameworks
But after creating a sample Swift project and comparing the build settings, Xcode was adding:
#loader_path/Frameworks
To the newly-created project. This was missing from my existing framework project. Adding it so the Runpath Search Paths contained these values solved the problem:
$(inherited)
#executable_path/../Frameworks
#loader_path/Frameworks
If you faced Library not loaded error in run time you should add those libraries in Embedded Binary.
Step 01 :-
Make sure that library is in the current project Navigation. If not Drag and drop library in to your project navigation.
Step 02 :-
Click on project > General > Embedded Binary > Add library which showed in your error. In this case you should add libswift_stdlib_core.
I'm trying to install a testing library for a project on top of SenTestingKit.
Prior to installing, the project builds fine and runs the test suite using SenTestingKit.
However, after using cocoapods to install another testing framework like Specta or Kiwi (which apparently depend on SenTestingKit), the project builds, but then immediately throws this error:
dyld: Library not loaded: #rpath/SenTestingKit.framework/Versions/A/SenTestingKit
Referenced from: [...]
Reason: image not found
I've tried about a dozen different suggestions from people with similar problems (changing the target build settings test host, changing the target framework search paths, etc, making sure pods are configured for the test target, etc.), all to no avail. Any suggestions?
Try with the following steps to link the static library to our project (which inturn uses a framework or static library):
Include the static library in the main projects "link binary with library".
Provided the header path at HEADER_SEARCH_PATH as well as LIBRARY_SEARCH_PATH (Inside Build Settings of app's target).
Most important:
In the target's build phases - > Link binaries with libraries set the relevant framework (SenTestKit.framework in our case) to "Optional" instead of "Required".
Hope this will fix your issue
Finally tracked down the answer.
Following the steps laid out in the answer here fixed the issue:
How to set dyld_library_path in Xcode
I have build a App based on OS X FUSE (ie I have my own file system based on OS X FUSE).
When OSXFUSE is installed I can of course include the OSXFUSE.framework from /Library/Frameworks.
However when I distribute the App I cannot expect the user to already have it installed, so I tried to include the framework with the bundle as follows:
dragged the framework from /Library/Frameworks to my project
created a new Copy Files build phase (with target Frameworks)
added the framework to that copy build phase
However when I run that on a system without FUSE installed I get an error:
dyld: Library not loaded: /Library/Frameworks/OSXFUSE.framework/Versions/A/OSXFUSE
Referenced from: /Users/me/Library/Developer/Xcode/DerivedData/
Shouldn't the copy build phase prevent this? What am I missing here?
I finally found out that I can tell XCode explicitly to weakly link a framework by changing the required flag to optional.
This can be done in Project Overview > Target > Linked Frameworks and Libraries. Next to each framework is a dropdown-menu where you can select optional.
So my question is actually a duplicate of this How do I weak link frameworks on Xcode 4?
I believe that the OSXFuse framework needs a corresponding kernel module to work. This has to be installed separately so you would have to put together an installer package that first installs the kernel module and the preferences pane, and then installs your application.
Alternatively, you could notify the user that the module needs to be installed separately and provide a download link or something to that effect.
One of my Mac applications contains a framework which I embed into the application bundle. Now I have found some evidence that on some customer machines the application links against the same framework located in the /System/Library/Frameworks folder.
I'm obviously missing something when it comes to linking the embedded framework to the application in XCode, so here's how I've done it.. and perhaps you can point me to the missing step:
1) I drag the framework project into my project and set up the dependency between both projects
2) I drag the build product of the framework project to the "Link Binary with Libraries" build phase of my target
3) I drag the build product of the framework project to the "Copy Framework Files" build phase of my target set to "Destination: Frameworks"
This all works great but somewhere I need to specify that I want to link with the embedded version of the framework rather than any framework version that might be found on the system. Is there a search path to be set somewhere? or "static" link?
Any help would be appreciated.
Best regards,
Frank
Sounds like you might be missing a key step. You also need to set the "install name" of your embedded framework.
When you link a framework or dynamic library, your app will look for the framework at the path specified by framework's install name. This should specify a relative path for embedded frameworks. If it is an absolute name it will pick up the system installed version, even if you've embedded the library.
To examine the install name do the following and look at the first location.
otool -L <framework-binary>
These two blog posts explain the issue and also how to set everything up properly:
http://www.mikeash.com/pyblog/friday-qa-2009-11-06-linking-and-install-names.html
http://www.dribin.org/dave/blog/archives/2009/11/15/rpath/
Additionally, if you're compiling a dylib from the command line (say an open source library) just add the following to your CFLAGS to set your install name.
-install_name '#rpath'
If you want to modify an existing binary's install name use 'install_name_tool'.
Also be sure your copy files build phase is copying the right files into the right places in your app bundle.