简体   繁体   中英

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

在此处输入图像描述

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

Here was the correct usage for me in Package.swift

How to link system framework/library in swift package

  targets: [
    .target(
      name: "SomeTarget",
      dependencies: [ ... ],
      linkerSettings: [
        .linkedFramework("PDFKit")
      ]
    ),
  ]

Note that LinkerSetting has both .linkedFramework(..) and .linkedLibrary(..)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM