5

I have locally built C library (.h and .a files) that I want to include in a Swift-based CocoaPods pod. How do I configure the podspec to depend on the .a files and the module.map? With a normal non-CocoaPods Xcode project, I simply drag in the directory that contains include and lib and then add a module.map. With CocoaPods I can't do this because pod install will overwrite the Xcode project file. s.library won't work because the the static library isn't hosted anywhere. I tried s.vendored_libraries but module.map still remains unknown to Xcode, the end result being that import foo from my Swift files is an error.

Edit: I tried using preserve_paths, vendored_libraries and xcconfig as answered here. The issue is still how to import the module from Swift.

Edit 2: I also tried using module_map to point to my module.map file as documented here, but sadly CocoaPods 1.1.1 crashes ([!] Oh no, an error occurred.).

1
  • Have you tried adding module to Import Paths under Swift Compiler – Search Paths in your project settings? Commented Jan 6, 2017 at 23:59

1 Answer 1

2

I got it working. In my case I'm depending the libtiff C library which is prebuilt for iOS (x86 and arm) using https://github.com/ashtons/libtiff-ios.

I used a subspec as outline here. Here's the podspec subspec snippet, assuming the static library lives at libtiff off the root of the pod module.

s.subspec 'libtiff' do |libtiff|
  libtiff.source_files = 'libtiff/include/*.h'
  libtiff.public_header_files = 'libtiff/include/*.h'
  libtiff.preserve_paths = 'libtiff/include/*.h'
  libtiff.vendored_libraries = 'libtiff/lib/libjpeg.a', 'libtiff/lib/libpng.a', 'libtiff/lib/libtiff.a', 'libtiff/lib/libtiffxx.a'
  libtiff.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/#{s.name}/libtiff/include/**" }
  # you can't specify "libz" here, must specify "z", see https://github.com/CocoaPods/CocoaPods/issues/3232
  libtiff.library = 'z'
end
Sign up to request clarification or add additional context in comments.

1 Comment

I had same requirement and done everything, but still getting some error Library not found for -l{libraryname} . Any inputs to fix it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.