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

Please ignore the code example above. While it produces the "objc[29459]: class `NSKVONotifying_AVCapturePhotoOutput' not linked into application" in the environment mentioned in the first post, the code itself is not correctly implemented for capturing a photo. I found a Swift implementation on Github that produces the same message, but works. I made a more robust example on my own and also made it work (I apologise for not being able to share it).

In short, the message might (I still do not know) not be harmful. The example above is incorrect, I'm guessing because of ill managed lifetime and/or because it does not take into account the setup time needed for the camera to become ready for capture.

class `NSKVONotifying_AVCapturePhotoOutput' not linked into application
 
 
Q