class `NSKVONotifying_AVCapturePhotoOutput' not linked into application

I get the message "objc[29459]: class `NSKVONotifying_AVCapturePhotoOutput' not linked into application" and I do not seem to be able to process a captured photo. Users on stackoverflow are seeing this too (using Swift): https://stackoverflow.com/questions/76893120/unable-to-capture-and-save-image-using-avcapturephotooutput-in-macos-app

I am running Ventura 13.0.1.

Minimal example:

#import <AVFoundation/AVFoundation.h>

@interface PhotoCaptureDelegate : NSObject <AVCapturePhotoCaptureDelegate>

@end

@implementation PhotoCaptureDelegate

- (void)captureOutput:(AVCapturePhotoOutput *)output didFinishProcessingPhoto:(AVCapturePhoto *)photo error:(nullable NSError *)error {
    if (error) {
        NSLog(@"Error capturing photo: %@", error.localizedDescription);
    } else {
        NSLog(@"Ready to process photo.");
    }
}

@end

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];
        
        AVCaptureDevice *captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        
        if (captureDevice) {
            NSError *error = nil;
            AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];
            
            if (!error) {
                [captureSession beginConfiguration];
                [captureSession addInput:input];
                
                AVCapturePhotoOutput *photoOutput = [[AVCapturePhotoOutput alloc] init];
                [captureSession addOutput:photoOutput];
                [captureSession commitConfiguration];
                
                [captureSession startRunning];
                
                // Create and configure a capture connection
                AVCaptureConnection *connection = [photoOutput connectionWithMediaType:AVMediaTypeVideo];
                if (connection) {
                    // Configure settings for the photo capture
                    AVCapturePhotoSettings *photoSettings = [AVCapturePhotoSettings photoSettings];
                    //[photoSettings setFlashMode:AVCaptureFlashModeAuto]; // Set the flash mode if needed
                    PhotoCaptureDelegate *photoCaptureDelegate = [[PhotoCaptureDelegate alloc] init];
                    [photoOutput capturePhotoWithSettings:photoSettings delegate:photoCaptureDelegate];
                    
                    // Capture a photo and delegate will receive the result
                }
            } else {
                NSLog(@"Error adding input: %@", error.localizedDescription);
            }
        } else {
            NSLog(@"No video capture device available");
        }
    }
    return 0;
}


Compile with:

$ clang -framework AVFoundation -framework Foundation -o test avphoto.m

Any thoughts?

Best regards,

Linus

class &#96;NSKVONotifying_AVCapturePhotoOutput' not linked into application
 
 
Q