Search code examples
dependenciessymbolsswiftpm

PDFKit symbols missing from Swift Package error


I am trying to build a swift package that has a dependency on a framework, but that downstream framework is throwing an error.

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_PDFDocument", referenced from:
      objc-class-ref in Slice.swift.o
      objc-class-ref in Utility.swift.o
  "_OBJC_CLASS_$_PDFPage", referenced from:
      objc-class-ref in Slice.swift.o
      objc-class-ref in Utility.swift.o
ld: symbol(s) not found for architecture x86_64

The downstream framework builds fine in isolation, but when it is added as a dependency to something else it's a pain.

It seems 'PDFKit' from the iOS or macOS SDK is not linked. How would I link that?

I tried adding the following to my code to see if it would make a difference, but it didn't.

#if os(macOS) 
import Quartz.PDFKit
#else
import PDFKit
#endif

The error suggests PDFKit needs to be listed in my Package.swift file ... ?

EDIT

The error is eliminated if I manually select 'PDFKit' here. However, this instance of Xcode was built with

swift package generate-xcodeproj

So manually changing things should not be necessary...

enter image description here


Solution

  • With help from the swift forum I managed to find an answer using this API.