How to link CocoaImageHashing pod with Swift project (dyld: Library not loaded) - swift

I'm trying to use the CocoaImageHashing pod from a Swift project so that I can do some perceptual hashing for image duplicate detection.
I setup the workspace following the CocoaPods instructions and attempted to run the default Hello World swift file.
dyld: Library not loaded: #rpath/CocoaImageHashing.framework/Versions/A/CocoaImageHashing
Referenced from: /Users/sarge/Library/Developer/Xcode/DerivedData/PHashTest-cdongczzcrynrfclysczwalanrlq/Build/Products/Debug/PHashTest
Reason: image not found
(lldb)
My Podfile is:
platform :osx, '10.12'
target 'PHashTest' do
use_frameworks!
pod 'CocoaImageHashing', :git => 'https://github.com/ameingast/cocoaimagehashing.git'```
end
I tried commenting out the use_frameworks! line in case this was some kind of dynamic library problem. I then get a build error.
Framework not found CocoaImageHashing
My General > Linked Frameworks and Libraries does include the CocoaImageHashing framework. I see Xcode building files from it during a build.
Is there something I have to do to get the CocoaImageHashing pod to build the dynamic library that Swift expects? Or do I need to not use Swift because CocoaImageHashing has to be included dynamically.
(I'm very unfamiliar with Swift so I don't know what to look for)

You should include the framework at General -> Embedded Binaries as well.

Related

XCFramework "Cannot load underlying module"

I've built an SDK as an XCFramework, which shares dependencies with the app that uses it. When I build, I'm getting:
...SDK.swiftmodule/arm64-apple-ios.swiftinterface:20:8: Cannot load underlying module for...
This occurs in the Compile Swift Sources action and the break is in the import MySharedDepedency statement in the swiftinterface file
As stated, the SDK in the project as an xcframework bundle. MySharedDependency is fulfilled with cocoapods. use_modular_headers is set in the Podfile, it's modulemap is included in the linker flags (by cocoapods).
Its DOES work if I use the use_frameworks! flag in the Podfile but only with dynamic linkage and for internal politics reasons, I need this to work with static linkage. If I add the :linkage => :static argument, I get the same error as with no use_frameworks! call
I've tried changing the order of the linked frameworks in Build Phases (so that the pods are linked before the SDK framework). I've tried adding recursive header/framework/module search paths everywhere I can find a MyDependency.modulemap...
Yes, I've cleaned caches, deintegrated, clean installed, erased deriveddata, restarted xcode, my machine, ...
Argh! Thanks for any help...
I had the same exactly the same scenario and the same problem
I solved using #_implementationOnly in every file from my xcframework's code like:
#_implementationOnly import Alamofire
After that just rebuild your XCFramework, clean and build your app's project.
It works like a charm without use_frameworks!

Linking dynamic library within static framework

I am building the static iOS framework upon multiple libraries in Xcode. One of them should be the card.io. I cannot use cocoapods or carthage. So far I imported .frameworks within the .framework and it works pretty well. However card.io uses static library (.a file) with bunch of headers. It works well in dynamic type of .frameworks (or iOS app project) but in static project I get these errors on including of the .a files:
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lCardIO
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lCardIO is not an object file (not allowed in a library)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lopencv_core
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lopencv_core is not an object file (not allowed in a library)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lopencv_imgproc
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lopencv_imgproc is not an object file (not allowed in a library)
Regarding these errors I downloaded the source codes of card.io and it looks that there is dynamic .framework target waiting for build. I tried to use this one instead of .a files and headers - so my project at least can be builded. Because the card.io does not contatin architectures for simulator (which, by the way, it should with this release 5.2.2) I am not able to test it in unit tests, so when I test this solution on device I get this error:
dyld: Library not loaded: #rpath/CardIO.framework/CardIO
Referenced from: /var/containers/Bundle/Application/55D3AF7F-83F4-4B3D-A667-0FCO93CCC441/App/AppDemo
Reason: no suitable image found.
So far my knowledge+google+stackoverflow is stuck here, because it looks that xcode does not support the .framework within .framework this way.
To this moment I spent two days with this "issue", so the question is: Does exist any solution for including dynamic library into static framework? Or any solution to include card.io into static framework?
EDIT:
Well actually the solution was more stupid than I would think (as always). Just to include card.io in the .framework go to "Project Description -> Build Settings -> Library search paths" and type the path where should xcode look for the libraries. This approach solves the first one issue of this post - this means the implementation of the .a libraries and headers.
At this moment I cannot guarantee it will work in releases based on my framework so I will update this post to confirm it later. I hope it helps someone...

How to add Cocoa pod dependency to custom framework swift

I am using GVRSDK library pod in my custom framework but if i add this some other project target its not getting import. I am using module map because the library was not getting import in custom framewotk
error: using bridging header with framework target is unsupported.
Compilation Error due to adding private header in umbrella header Include of non modular header inside framework module .
Next i added Module Map File it got imported in Framework swift file. If i
import it in some other swift target it throwing error module not found.
You should speciafied in your Podfile for which target you wanna install your pods
target 'FrameworkName' do
use_frameworks!
pod 'GVRSDK'
end
After that you can add the framework to your app from Build Phases -> Embed Frameworks

Why I cant import the library that in swift file after installing the the dependency in Cocoapods?

I already install this library, XLPagerTabStrip via Cocoapod. My pod file is look like this,and already hit pod install in terminal.
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'MyProject' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for MyProject
pod 'XLPagerTabStrip', '~> 8.0'
end
So everything is completed install,but when I want to import the library in Swift file,it giving an error ->> No such module 'XLPagerTabSript'.
I read a lot of question about this,which mention add the file path of the library to
Build Setting -> Search Paths -> User Header Search Paths. I also already did,but still giving the same error.
What I add in User Header Search Path is something like this:
${SRCROOT}/Users/Myname/Desktop/MyProject/Pods/XLPagerTabStrip
After adding the file path,I clean the project,build the project again,the tried to add in import XLPagerTabStrip to one of my swift file,the error still the same.
Can somebody let me know what is problem actually? Cause I beginner in Ios development,I totally no idea what I doing wrong.
I end up solve it by update my Xcode vesion and insert the file path of the library in inside
Build Setting -> Search Paths -> Framework Search Paths -> (Add the
file path of the library here)
By this I can import the library in swift file without any warning

Library not found for -lFirebase after installing XLForm

I have a project in Swift where I use some libraries. When I run on the simulators or on the physical device, it runs perfectly. But by the time I try to archive the project to send it to the store, I receive the following error message:
ld: library not found for -lFirebase
The problem is when I use the XLForm library, which was the last modification I have done to my Podfile.
I am using the .xcworkspace since I started using the CocoaPods, and I have never had any problem before.
My Podfile:
# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
# use_frameworks!
pod 'Firebase', '= 2.5.0'
pod 'Google/CloudMessaging'
pod 'Google'
pod 'Google/Analytics'
pod 'XLForm', '~> 3.0'
target 'Dimmi' do
end
target 'DimmiTests' do
end
target 'DimmiUITests' do
end
The XLForm library does not depends on any other library or framework. Also, I tried to install it manually with no success.
You need to create a bridging header file and import the Objective-C framework through it.
Create a new header file and name it in the following pattern:
ProjectName-Bridging-Header.h
Then add your framework header to it
#import Framework.h
Then add the bridging header to your build settings under Objective-C Bridging Header.