Reputation: 2028
I'm trying to create Pod which depends on static library (.a file + headers whose structure should be preserved for my pod compilation) and I don't want to link my static library to Application that will be using my pod, it's only internal dependency, no headers or lib itself should be exposed outside of Pod. How do I create podspec for this situation?
Upvotes: 1
Views: 1123
Reputation: 2028
I ended up with wrapping my static library with headers into framework folder and adding this framework to vendored_frameworks podspec field and adding header search path
s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(FRAMEWORK_SEARCH_PATHS)/FrameworkName.framework/Headers" }
Alongside with CocoaPods I'm able to link my binary and headers separately to Xcode framework target and distribute my library using Carthage
Upvotes: 1
Reputation: 1306
Looks like this will get a bit messy... One way would be to recompile the static lib to a dylib, and then load the symbols on demand. By doing so you won't have to touch the .podspec file. I assume you are using Swift 3 and want to load C functions from the library.
If you do not have the source or otherwise can't recompile the static lib, you could convert it to a dylib by using this guide.
I will add an example on how to dynamically load the CCHmac
function from libcommonCrypto.dylib
/// - Returns: A function pointer to CCHmac from libcommonCrypto
private static func loadHMACfromCommonCrypto() -> CCHmac
{
let libcc = dlopen("/usr/lib/system/libcommonCrypto.dylib", RTLD_NOW)
return unsafeBitCast(dlsym(libcc, "CCHmac"), to: CCHmac.self)
}
In case that you can't/won't load the symbols from the header file, you will have to define them yourself.
private typealias CCHmac = @convention(c) (
_ algorithm: CUnsignedInt,
_ key: UnsafePointer<CUnsignedChar>,
_ keyLength: CUnsignedLong,
_ data: UnsafePointer<CUnsignedChar>,
_ dataLength: CUnsignedLong,
_ macOut: UnsafeMutablePointer<CUnsignedChar>
) -> Void
Upvotes: 0