Xcode -" ld: framework not found" happening on a framework not included directly - ios

A bit of story:
I created a framework called, Notifications, that allows our iOS applications to use one of our new backend service. I created the framework in Swift, and included it in our main application which is written in Obj-C. This was working great until one of my colleauges updated the main application to allow us use Swift in the main application.
I am now getting the following error:
ld: framework not found ISO8601 for architecture x86_64
This is a rather interesting error as the Notifications framework uses ISO8601, and it is included in the Notifications framework. The main application does not reference this framework at all.
Yes, I did check to make sure ISO8601 has has the x86_64 architecture, and all included frameworks, and the Notifications framework also has all the required architectures.
I looked at the build settings and they appear to be all in line with building the project as expected.
For me the only difference appears to be enabling Swift in the main app. I have cleaned, deleted derived data, and various build settings trying to get it working.
Any thoughts or ideas for fixes would be greatly appreciated.

Related

Undefined symbols for architecture x86_64: xcode 9 Swift 4

I create app that uses Huawei SDK written in Objc with updated docs in Oct 2017. But when I add framework to project, this shows me stange error. I have stack on this problem couple days, I have tried everything from similar problems, but nothing helped for me.
Framework added correctly(header file, link binary with libraries) autocomplition works well and shows the methods when trying to use SDK.
Already tried: change/edit/update
Valid architecture: arm, armv, armv7, armv7s, i386, x64_86
Clean Derived date and achieves
Restart OS
Change swift version: Shows another error
Checked ObjC bridging header
Pod update/install
Framework search path
SOLUTION:
Launch on real device=)
Looks like your HWMobileSDK.framework is not a fat framework. You'll either need to find a fat framework, or a second build of the framework that's compiled for the simulator (x86_64). I couldn't find any reference to that framework online, so it looks like it's not publicly available. If you got this from Huawei directly, you should ask the person you're in contact with there. Either they don't provide a version of the library for the simulator and you'll need to develop using a device only, or you need another version of the library.

dyld: Library not loaded: #rpath/libswiftSwiftOnoneSupport.dylib

I've built a Swift framework and now I'm trying to start building a Swift iOS application that will use that framework. I'm getting this error:
dyld: Library not loaded: #rpath/libswiftSwiftOnoneSupport.dylib
Referenced from: /Users/tdean/Library/Developer/Xcode/DerivedData/NFLApplication-ejmafvjrlqgjaabggwvadjarjjlg/Build/Products/Debug-iphonesimulator/NFLStatsModel.framework/NFLStatsModel
Reason: image not found
I've scoured SO and found similar reports and tried the fixes listed there, including:
Clearing out my DerivedData folder
Restarting Xcode and the iPhone simulator
Ensuring that Always Embed Swift Standard Libraries = YES is set, both in my framework and my application's build settings
Ensuring that Enable Bitcode=NO is set, both in my framework and my application's build settings
Ensuring that Runpath Search Paths is set to #executable_path/Frameworks, both in my framework and my application's build settings
Copied all the libswift files from my Xcode installation into a local copy within my project, and added a custom build phase to copy those files into the frameworks folder.
In every case, I get the same error when I try to run my application.
Xcode Version 8.1 (8B62)
Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1)
I eventually got this working using a mix of fixes. I'm not sure if all of them are needed, but I'm documenting what seemed to work for me here, just in case anyone else can benefit by what I've found.
I have set Always Embed Swift Standard Libraries to a value of YES in the build settings tab for both my Swift framework and in the Swift application that uses the framework.
I have added Foundation.framework to the Linked Frameworks and Libraries section of the general tab for both my Swift framework and in the Swift application that uses the framework.
I have added Foundation.framework to the Embedded Binaries section of the general tab for the Swift application that uses the framework.
With all 3 of these settings in place, I am able to build and run my application without encountering this error.
This might not be the case for everyone, but I solved it by actually writing some code in the main target.
I had an empty project consisting of a framework and a test target, and when running tests I was getting this error. Apparently Swift is pretty smart to detect that you don't actually need this library and does not link to libswiftSwiftOnoneSupport.dylib.
The fix is just to add some code, I just added:
class Test {
func a() { print ("something") }
}
and libswiftSwiftOnoneSupport.dylib got linked.
After several days of being stuck with this issue I finally found something that worked for me; hopefully this will help others too.
Turns out that specifically using print() anywhere in the code will somehow force libswiftSwiftOnoneSupport.dylib to be loaded and the issue will go away.
I'm using Xcode 10.1, Swift 4.2 and the pod that was giving me this issue was Nimble.
BTW, I am aware of #S2dent's suggestion to "just add some code" but in my case my framework already had several different classes so it didn't help me.
How are you installing your dependencies?
I had a similar issue:
dyld: Library not loaded: #rpath/libswiftSwiftOnoneSupport.dylib
Referenced from: <internal framework>
Reason: image not found
It turned out to be related to Swift whole-module optimization.
Using Carthage as a dependency manager, they were being compiled for Release, and thus compiled with whole-module optimization, which Xcode suggested I turn on. Running the app on the simulator compiles it for Debug. I'm guessing that dynamic frameworks cannot be at a different level of optimization from the app running it.
The solution was to explicitly specify the configuration I wanted Carthage to build for. (carthage bootstrap --configuration Debug) Oh, and cleaning my build folder, of course.
I had the same issue, adding the library (my own build one) to Linked Frameworks and Libraries in General tab of the app solved the issue.
You can also provide an Host Application to your test target if you don't want to add Foundation.framework to Linked Frameworks or Embedded Binaries
You can solve this by setting "Always Embed Swift Standard Libraries" to "Yes" in the Build Settings of your target.
It is an dynamic linker error which links binary in load or runtime
[#rpath]

Using pre compiled dylib in iOS8+ or building dynamic framework out of dylibs?

I'm trying to use a fat dylib I've made that contains the latest version of tbb with code for all architectures I may be targetting (armv7, arm64, i386 and x86_x64)
Since iOS8 using dylib(s) is meant to be possible, in fact one of the error messages I found googling was the following one:
ld: embedded dylibs/frameworks are only supported on iOS 8.0 and later
Which seems to suggest that embedding dylibs is actually possible and we aren't only restricted to the new so called dynamic frameworks, yet, when I try to run my project I get the following:
dyld: Library not loaded: #rpath/libtbb.dylib
Referenced from: /Users/user/Library/Developer/CoreSimulator/Devices/B4DCFF3E-10B2-4C01-953F-BD26D14300E7/data/Containers/Bundle/Application/8C84A844-97FC-4993-A37E-A456C4E2240F/TestTBB.app/TestTBB
Reason: image not found
I thought it would be due to the dylib not being automagically copied into the app being built so I added it to the "Copy Bundle Resources" section in the projects "Build Phases" and I've since made sure that the libtbb.dylib is in fact being copied into the app and yet I keep getting the message saying that it can't be loaded.
I've tried using the "Embedded Binaries" section under "General" but it seems to be restricted to using only the new framework types.
Is there anything I might be missing?
As you may have noticed I'm trying to use TBB which comes with its own build makefiles that generates dylibs, I'm assuming that if it does it's because dylibs can be used, legally since the iOS8+ update.
I have seen ways of getting dylibs to load, but these aren't the ones that Apple would accept in their AppStore, I'm trying to do this for an app that is currently on the AppStore and I have no plans of getting it removed or not accepted after an update so I'd like to go with whatever the new "legal" way is to get dylibs loaded. My app is targetting iOS9.2+ since the latest update so this shouldn't be an issue.
All I can find are ways to get dynamic frameworks loaded but no info about actual dylibs even though the error message clearly states that they could be used.
Alternatively, is there a way to build a dynamic framework out of existing dylib files?
Thanks in advance.

How to build iOS framework with XCode 6

I know of familiar tutorials on this, but introduction of framework XCode 6 template has changed the game.
I already watched WWDC 2014 video about building modern frameworks but it talks more about building extensions, framework & app all inside single project. It does not specify if the framework I make with it is truly reusable across any project.
I am building framework the XCode 6 way (File->New Project->Framework and Library->Cocoa Touch Framework), but when I import it inside my test app project (separate from framework project) - I keep getting various errors.
Example: Include of non-modular header inside framework, and so on.
I know this is not what it says, and there are quite some missing steps in whatever I am doing. The older tricks may have worked for everyone, but I simply don't find which way to follow after XCode 6.
For example, there is some folder structure that a framework needs, but XCode 6 doesn't comply to it while building it. Is it right? If not, how can I change the way the XCode builds framework folder hierarchy?
Do I go back to old school or am I screwing some tiny thing in XCode 6 that I am unable to create a reusable framework?
I am not sure if you are trying to build a framework with Objective-C or Swift as your question doesn't state it. I've encountered errors you are mentioning with Swift so I'll give you my method to build Swift frameworks.
I found the process for Objective-C to be very straightforward and well documented, so I'll skip this.
As for Swift, there are a few things to consider. First, Swift static libraries are not supported, so you must exclusively use a framework (aka dynamic library) when linking an app to a library.
Here are the steps:
Create the Framework using New > Project under IOS > Framework & Library, select Cocoa Touch Framework
To avoid the "ld: warning: directory not found for option..." goto Library Search Paths in Build Settings for your target and delete the paths.
You can't mix Objective-C with Swift so don't even consider adding the Swift-Header bridge file in your code.
There are some cases in swift where you need to import code from unexposed Frameworks. I've successfully used the module-map inside the framework to deal with these case.
I also select CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES in the Build Settings to solve 'include of non-modular header inside framework module'. That seems to work
I make sure that the header file that gets generated is marked as Public (not Project). Click on the file and you'll see the selection in the inspector under 'Target Membership'
You may run into some bizarre error messages when building. Xcode has a tendency to report linker errors when your code can't compile correctly resulting in missing files the linker needs to output its binaries. Sometimes XCode won't show the errors in the files you are compiling and you need to go manually on the build output and go back to the files. Some other time, you'll get a problem where you need to delete the cache. Those issues I call XCode blues and deal with it constantly. I found this type of problems happens more often when building libraries. The rest should work as expected.

How can code using a framework class run without the framework?

I'm running an app that uses EAAccessoryManager, which should only be available via the ExternalAccessory framework. Yet it compiles and runs without ExternalAccessory being included in the list of frameworks to link. Nor is it loaded into Xcode by any other targets. How is this possible? I'm mystified.
I'm curious because I have another project that loads a static library that also references EAAccessoryManager, and in that case, the app won't compile, exiting with the error Undefined symbols for architecture i386. This is more what I expect. What can account for the difference?
Could be a linker build setting rather than a link build phase.
In Build Settings, in the “Apple LLVM 5.1 – Languages – Modules” section, “Link Frameworks Automatically” is enabled:
This is a new feature I never noticed before discovered while reading this post on #import (thanks #RhythmicFistman for the hint!). When I change that setting to “No”, I get the linker errors I expect.

Resources