Objective-C中架构x86_64的未定义符号 [英] Undefined symbols for architecture x86_64 in Objective-C

查看:69
本文介绍了Objective-C中架构x86_64的未定义符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Xcode项目中实现此处找到的AVFoundation示例代码:

I am attempting to implement the AVFoundation example code found here in an Xcode project: http://developer.apple.com/library/mac/#qa/qa1740/_index.html#//apple_ref/doc/uid/DTS40011007

我所做的唯一修改是删除了对自动发布,发布和保留的引用,因为我为项目启用了自动引用计数.成功解决了这些构建错误之后,我现在得到体系结构x86_64的未定义符号".

The only modifications I have made were to remove references to autorelease, release, and retain because I have automatic reference counting enabled for the project. Having successfully resolved those build errors, I am now getting "Undefined symbols for architecture x86_64".

我在Mountain Lion 10.8上运行,并且在将AVFoundation.h导入头文件时没有出现任何错误,但是好像找不到AV *符号吗?

I am running on Mountain Lion 10.8, and get no errors when importing AVFoundation.h into my headers file, but it seems like the AV* symbols are not being found?

下面是错误日志,.h和.m代码.知识渊博的人可以帮助我确定问题的根源吗?

Below is the error log, .h, and .m code. Could someone more knowledgable help me identify where the issue(s) lie?

日志:

Undefined symbols for architecture x86_64:
  "_AVCaptureSessionPresetMedium", referenced from:
      -[Recorder screenRecording:] in screenAppDelegate.o
  "_OBJC_CLASS_$_AVCaptureMovieFileOutput", referenced from:
      objc-class-ref in screenAppDelegate.o
  "_OBJC_CLASS_$_AVCaptureScreenInput", referenced from:
      objc-class-ref in screenAppDelegate.o
  "_OBJC_CLASS_$_AVCaptureSession", referenced from:
      objc-class-ref in screenAppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

.h

#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

@interface screenAppDelegate : NSObject <NSApplicationDelegate>
@end

@interface Recorder : NSObject <AVCaptureFileOutputRecordingDelegate> {
    @private AVCaptureSession *mSession;
    AVCaptureMovieFileOutput *mMovieFileOutput;
    NSTimer *mTimer;
}

-(void)screenRecording:(NSURL *)destPath;

@end

.m

#import "screenAppDelegate.h"

@implementation screenAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
}

@end


@implementation Recorder

-(void)screenRecording:(NSURL *)destPath 
{
    // Create a capture session
    mSession = [[AVCaptureSession alloc] init];

    // Set the session preset as you wish
    mSession.sessionPreset = AVCaptureSessionPresetMedium;

    // If you're on a multi-display system and you want to capture a secondary display,
    // you can call CGGetActiveDisplayList() to get the list of all active displays.
    // For this example, we just specify the main display.
    CGDirectDisplayID displayId = kCGDirectMainDisplay;

    // Create a ScreenInput with the display and add it to the session
    AVCaptureScreenInput *input = [[AVCaptureScreenInput alloc] initWithDisplayID:displayId];
    if (!input) {
        //[mSession release];
        mSession = nil;
        return;
    }
    if ([mSession canAddInput:input])
        [mSession addInput:input];

    // Create a MovieFileOutput and add it to the session
    mMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
    if ([mSession canAddOutput:mMovieFileOutput])
        [mSession addOutput:mMovieFileOutput];

    // Start running the session
    [mSession startRunning];

    // Delete any existing movie file first
    if ([[NSFileManager defaultManager] fileExistsAtPath:[destPath path]])
    {
        NSError *err;
        if (![[NSFileManager defaultManager] removeItemAtPath:[destPath path] error:&err])
        {
            NSLog(@"Error deleting existing movie %@",[err localizedDescription]);
        }
    }

    // Start recording to the destination movie file
    // The destination path is assumed to end with ".mov", for example, @"/users/master/desktop/capture.mov"
    // Set the recording delegate to self
    [mMovieFileOutput startRecordingToOutputFileURL:destPath recordingDelegate:self];

    // Fire a timer in 5 seconds
    mTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(finishRecord:) userInfo:nil repeats:NO];
}

-(void)finishRecord:(NSTimer *)timer
{
    // Stop recording to the destination movie file
    [mMovieFileOutput stopRecording];

    //[mTimer release];
    mTimer = nil;
}

// AVCaptureFileOutputRecordingDelegate methods

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error
{
    NSLog(@"Did finish recording to %@ due to error %@", [outputFileURL description], [error description]);

    // Stop running the session
    [mSession stopRunning];

    // Release the session
    //[mSession release];
    mSession = nil;
}

推荐答案

仅导入头文件还不够,您还必须将AVFoundation框架添加到项目中.此错误来自链接器,而不是编译器本身-可以找到AVFoundation标头,并且源文件的编译成功,但是由于您没有告诉您,链接器无法从生成的目标文件中生成可执行文件(通过Xcode的设置)以链接到AVFoundation框架.

It's not enough to import header files, you also have to add the AVFoundation framework to your project. This error comes from the linker, not from the compiler itself - the AVFoundation headers could be found and the compilation of your source files was successful, but the linker couldn't make an executable out of the resulting object files as you haven't told it (through Xcode's settings) to link against the AVFoundation framework.

请参见有关编译过程的本文,以了解为什么这样做发生.

See this article on the compilation process to understand why this happens.

这篇关于Objective-C中架构x86_64的未定义符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆