Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CocoaPods project depend on a local static C library

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.).

like image 371
Steve Kuo Avatar asked Nov 09 '22 03:11

Steve Kuo


1 Answers

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
like image 189
Steve Kuo Avatar answered Nov 14 '22 22:11

Steve Kuo