【发布时间】:2017-09-14 19:53:46
【问题描述】:
我有一个普通的UIViewController,它使用AVCapturePhoto,我在其中创建了一个自定义捕获控制器。
在我更新到 Xcode 9 并将我的代码转换为 Swift 4 之前一切正常,现在当我尝试编译时,我得到了这个编译错误:
架构 x86_64 的未定义符号: “__T0So22AVCapturePhotoSettingsC12AVFoundation01_abC16SwiftNativeTypesACWP”,引用自: __T05Union16CameraControllerC18handleCapturePhotoyyF 在 CameraController.o “__T012AVFoundation39_AVCapturePhotoSettingsSwiftNativeTypesPAAE016availablePreviewc11PixelFormatG0Says6UInt32VGfg”,引用自: __T05Union16CameraControllerC18handleCapturePhotoyyF 在 CameraController.o ld:未找到架构 x86_64 的符号 clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
并且在错误托盘中显示此消息:
Apple Mach-O 链接器错误组
任何提示可能是什么原因造成的?
更新信息
这是错误日志的 Xcode 9 打印屏幕。希望对编译错误解决方案有所帮助。
编辑
只是执行一些测试——如果我注释类代码,编译错误就会消失。
我在Swift 4 中缺少的以下class 实现有什么问题吗??
import UIKit
import AVFoundation
class CameraController: UIViewController, AVCapturePhotoCaptureDelegate, UIViewControllerTransitioningDelegate {
let dismissButton: UIButton = {
let button = UIButton(type: .system)
button.setImage(#imageLiteral(resourceName: "right_arrow_shadow").withRenderingMode(.alwaysOriginal), for: .normal)
button.addTarget(self, action: #selector(handleDismiss), for: .touchUpInside)
return button
}()
let capturePhotoButton: UIButton = {
let button = UIButton(type: .system)
button.setImage(#imageLiteral(resourceName: "capture_photo").withRenderingMode(.alwaysOriginal), for: .normal)
button.addTarget(self, action: #selector(handleCapturePhoto), for: .touchUpInside)
return button
}()
let output = AVCapturePhotoOutput()
override func viewDidLoad() {
super.viewDidLoad()
transitioningDelegate = self
setupCaptureSession()
setupHUD()
}
// hiddes the status bar
override var prefersStatusBarHidden: Bool { return true }
//MARK: General funcs
fileprivate func setupCaptureSession() {
let captureSession = AVCaptureSession()
//1. setup inputs - camera
let captureDevice = AVCaptureDevice.default(for: AVMediaType.video)
do {
let input = try AVCaptureDeviceInput(device: captureDevice!)
if captureSession.canAddInput(input) {
captureSession.addInput(input)
}
} catch let err {
print("Could not setup camera input:", err)
}
//2. setup outputs
if captureSession.canAddOutput(output) {
captureSession.addOutput(output)
}
//3.setup output preview
let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.frame = view.frame
view.layer.addSublayer(previewLayer)
// starts the inputs/outputs
captureSession.startRunning()
}
fileprivate func setupHUD() {
// botão de captura
view.addSubview(capturePhotoButton)
capturePhotoButton.anchor(top: nil, left: nil, bottom: view.bottomAnchor, right: nil, paddingTop: 0, paddinfLeft: 0, paddingBottom: 24, paddingRight: 0, width: 80, height: 80)
capturePhotoButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
// dismiss button
view.addSubview(dismissButton)
dismissButton.anchor(top: view.topAnchor, left: nil, bottom: nil, right: view.rightAnchor, paddingTop: 12, paddinfLeft: 0, paddingBottom: 0, paddingRight: 12, width: 50, height: 50)
}
@objc func handleCapturePhoto() {
// processes the captured photo
let settings = AVCapturePhotoSettings()
guard let preview = settings.availablePreviewPhotoPixelFormatTypes.first else { return }
settings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String: preview]
output.capturePhoto(with: settings, delegate: self)
}
@objc func handleDismiss() {
dismiss(animated: true, completion: nil)
}
// Camera delegate
func photoOutput(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhoto photoSampleBuffer: CMSampleBuffer?, previewPhoto previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) {
// access the captured image
let imageData = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: photoSampleBuffer!, previewPhotoSampleBuffer: previewPhotoSampleBuffer!)
let previewImage = UIImage(data: imageData!)
// shows the image
let containerView = PreviewPhotoContainerView()
containerView.previewImageView.image = previewImage
view.addSubview(containerView)
containerView.anchor(top: view.topAnchor, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, paddingTop: 0, paddinfLeft: 0, paddingBottom: 0, paddingRight: 0, width: 0, height: 0)
}
}
【问题讨论】:
-
您的未定义符号将分解为
protocol witness table for __ObjC.AVCapturePhotoSettings : AVFoundation._AVCapturePhotoSettingsSwiftNativeTypes in AVFoundation -
@KevinBallard 抱歉,但我对您的评论有点迷茫。你是说我需要遵守 AVCapturePhotoSettings 协议?
-
我很困惑为什么这是另一个问题的重复。在我的 iphone7 上测试时出现了这个错误。将其标记为重复的人喝醉了!我找到了几种不使用该代码来解决我的问题的方法,#if arch(x86_64)
-
一种方法是在苹果意外私有化的一些 AVFoundation 类之前添加 2 个
_(下划线)。例如将settings.availablePreviewPhotoPixelFormatTypes.first else更改为settings.__availablePreviewPhotoPixelFormatTypes.first else。来源:forums.developer.apple.com/thread/86810#259270 -
这个错误的正确重复是这个stackoverflow.com/questions/45668293/…