3

I'm trying to fit MuPDF into a podspec. That's not going as good as I want it to though...

error: could not build module 'UIKit'

This is the error I get every time I try to pod lib lint. I get it in two flavours though, depending on the exact contents of the podspec. But before that, some context!

tl;dr: My brain can't process MuPDF and its static library dependencies to make a nice podspec out of it. Can you help?


File layout

So the library is MuPDF (http://mupdf.com); I cloned their git repository. It comes with a bunch of .m files, but the main library is written in C and has several dependencies. So we end up with a few static libraries (.a files). The file layout looks something like this:

mupdf/
  # objc files
  platform/ios/common.{h,m}
  platform/ios/Classes/*.{h,m}

  # headers and static libraries
  include/**/*.h
  platform/ios/thirdparty/*.a

The include folder contains the headers required by the libraries in platform/ios/thirdparty. These headers are included by platform/ios/common.h.

Podspec

And my podspec looks something like this:

Pod::Spec.new do |s|
  # <enter usual podspec yada yada here>

  s.source_files  = "platform/ios/Classes/**/*.{h,m}", "platform/ios/common.{h,m}", "include/**/*.h"
  s.public_header_files = "platform/ios/Classes/**/*.h"
  s.header_mappings_dir = "include"

  s.libraries = "z"
  s.vendored_libraries = "platform/ios/thirdparty/*"
end

Based on that (and a variation of the podspec), I get two different errors.

Symbol redefinition error

With this exact podspec configuration, I get the following errors:

- ERROR |  /<path>/mupdf/include/mupdf/fitz/math.h:97:8:
           error: redefinition of 'fz_point_s'
- NOTE  |  /<path>/mupdf/include/mupdf/fitz/math.h:97:8:
           note: previous definition is here
- ERROR |  /<path>/mupdf/include/mupdf/fitz/math.h:121:8:
            error: redefinition of 'fz_rect_s'
- NOTE  |  /<path>/mupdf/include/mupdf/fitz/math.h:121:8:
           note: previous definition is here

# etc. etc.

- NOTE  |  Target Support Files/Pods-mupdf/Pods-mupdf-prefix.pch:2:9:
           fatal error: could not build module 'UIKit'

Circular dependency error

If I comment out the s.public_header_files line, I end up with a circular dependency error. So weird!

- NOTE  |  /privateTarget Support Files/Pods-mupdf/Pods-mupdf-umbrella.h:1:9:
           fatal error: cyclic dependency in module 'UIKit':
           UIKit -> Foundation -> CoreFoundation -> MuPDF -> UIKit

Conclusion

My brain hurts, please help!

aspyct
  • 3,625
  • 7
  • 36
  • 61
  • Can i download your project somewhere? Since you add MuPDF and that one has a viral copy-left license, yours is also automatically under the Affero GNU GPL v3 (which btw, is incompatible with the App Store, so you legally can't submit your app) – steipete Jul 08 '15 at 10:20

2 Answers2

4

I am not really sure what is going on with your PodSpec, sorry. It is probably something to do with how you resolved the math.h header file conflict - it is annoyingly tricky to get this right in a pod spec.

I have just created a CocoaPod for MuPDF, and created an example application based on that pod, and all seems to work fine.

For reference here is my pod spec (note that this is now out of date; please refer to the published mupdf pod spec for one compatible with the latest version of mupdf and latest CocoaPods):

# podspec for MuPDF
#
# Copyright (C) 2015 Joseph Heenan <joseph@heenan.me.uk>

Pod::Spec.new do |s|
  s.name             = "MuPDF"
  s.version          = "1.7"
  s.summary          = "A lightweight PDF and XPS viewer."
  s.description      = <<-DESC
                       MuPDF is a small, fast, and yet complete PDF viewer. 
                       It supports PDF 1.7 with transparency, encryption, 
                       hyperlinks, annotations, searching and more. It also
                       reads XPS and OpenXPS documents.
                       DESC
  s.homepage         = "http://www.mupdf.com/"
  s.license          = { :type => "Affero GNU GPL v3", :file => 'COPYING' }
  s.author           = "Artifex Software Inc"
  s.source           = { :git => "https://github.com/ArtifexSoftware/mupdf.git", :tag => s.version.to_s }

  s.platform     = :ios, '6.1'
  s.requires_arc = false

  s.source_files = 'platform/ios/Classes/**/*.[mh]', 'platform/ios/common.[mh]'
  s.resources = 'platform/ios/*.png', 'platform/android/res/drawable-ldpi/*.png'

  s.public_header_files = "platform/ios/Classes/**/*.h", "platform/ios/common.h"

  # See https://github.com/CocoaPods/CocoaPods/issues/1437
  s.preserve_paths = "include/*", "include/**/*"

  s.prepare_command = <<-CMD
      # I tried --depth 1 here but it failed with git error "fatal: reference is not a tree:"
      git submodule update --init
      cd platform/ios

      # build the various .a files
      # release armv7 + arm64
      xcodebuild -scheme MuPDF -configuration Release CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
      # release i386 + x86_64
      xcodebuild -scheme MuPDF -configuration Release -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO

      # combine into fat libraries
      cd ../../build/
      for i in curl freetype jbig2dec jpeg mujs mupdf openjpeg z; do
          LIB=lib${i}.a
          lipo -create -output $LIB release-ios-i386-x86_64/$LIB release-ios-armv7-arm64/$LIB
      done
CMD

  s.vendored_libraries = "build/*.a"

  s.xcconfig = {
    # we have a math.h which conflicts with the system math.h unless
    # we disable header maps
    'USE_HEADERMAP' => 'NO',
    'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/Target Support Files/Pods"',

    'USER_HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/MuPDF/include"',

    'ALWAYS_SEARCH_USER_PATHS' => 'NO'
  }

end
JosephH
  • 37,173
  • 19
  • 130
  • 154
0

I solved the issue by deleting and adding UIKit.framework in Build Phases -> Link Binary With Libraries and set project's minimum iOS Version was 6.0.

Sandeep Agrawal
  • 425
  • 3
  • 10
  • 1
    Doesn't work sadly. I tried adding UIKit, Foundation and CoreFoundation to `s.frameworks` but it didn't solve it either. – aspyct Jun 04 '15 at 07:43