简体   繁体   English

链接器错误OBJC_CLASS _ $ _ AVAudioPlayer”

[英]Linker Error OBJC_CLASS_$_AVAudioPlayer"

Hello Everyone, 大家好,

[Error: objc-class-ref in ViewController.o
    ld: symbol(s) not found for architecture i386
    clang: error: linker command failed with exit code 1 (use -v to see invocation)] 

I am running an application which will produce sound after button is clicked ,

I have included all the framework for audio after seeing the error 看到错误后,我已经包含了所有音频框架

 [ objc-class-ref in ViewController.o
        ld: symbol(s) not found for architecture i386
        clang: error: linker command failed with exit code 1 (use -v to see invocation)
        ]

from stack overflow but still its not working for me .. please look at the below code i have included my .h and .m file and suggest me some solution 从堆栈溢出,但仍然对我不起作用..请查看下面的代码,我已包含我的.h和.m文件,并建议我一些解决方案

It May be an linker error but i have included the framework from build phase and included #import framework ..Please check out my below Code if i am missing something please let me know ... I am self learning beginner for iPhone Development .. 这可能是一个链接器错误,但我已经从构建阶段开始包含框架,并包含了#import框架..如果我缺少某些内容,请查看下面的代码,请让我知道...我是iPhone开发的自学入门。

        //  ViewController.h



        //  Audioplaying
        //
        //  Created by Vaibhav on 12/31/12.
        //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
        //

        #import <UIKit/UIKit.h>
        #import <AVFoundation/AVAudioPlayer.h>
         #import <AudioToolbox/AudioToolbox.h>


        @interface ViewController : UIViewController <AVAudioPlayerDelegate >

        {
            AVAudioPlayer *player;
            UIButton *playButton;
        }

        @property (nonatomic, retain) AVAudioPlayer *player;
        @property (nonatomic, retain) IBOutlet UIButton *playButton;

        - (IBAction) play;

        @end


    //
    //  ViewController.m
    // 
    #import "ViewController.h"
    #import <AVFoundation/AVAudioPlayer.h>

    @implementation ViewController

    @synthesize player, playButton;


    - (void)viewDidLoad {

        // grab the path to the caf file
        NSString *soundFilePath =
        [[NSBundle mainBundle] pathForResource: @"blip"
                                        ofType: @"caf"];

        NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];

        // create a new AVAudioPlayer initialized with the URL to the file
        AVAudioPlayer *newPlayer =
        [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];


        // set our ivar equal to the new player
        self.player = newPlayer;


        // preloads buffers, gets ready to play
        [player prepareToPlay];
        // set delegate so we can get called back when the sound has finished playing
        [player setDelegate: self];

        [super viewDidLoad];
    }

    // delegate method
    - (void) audioPlayerDidFinishPlaying: (AVAudioPlayer *) player
                            successfully: (BOOL) completed {
        if (completed == YES) {
            self.playButton.enabled = YES;
        }
    }


    // 
    - (IBAction) play {

        self.playButton.enabled = NO;
        [self.player play];

    }
    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    }

    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    }

    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
    }

    - (void)viewDidDisappear:(BOOL)animated
    {
        [super viewDidDisappear:animated];
    }

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // Return YES for supported orientations
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    }

    @end

Error : 错误:

Build target Audioplaying

Ld /Users/vaibhav/Library/Developer/Xcode/DerivedData/Audioplaying-eaaytfuwbstsyffgakkifipcygeu/Build/Products/Debug-iphonesimulator/Audioplaying.app/Audioplaying normal i386
    cd "/Users/vaibhav/Iphone projects/Audioplaying"
    setenv MACOSX_DEPLOYMENT_TARGET 10.6
    setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -L/Users/vaibhav/Library/Developer/Xcode/DerivedData/Audioplaying-eaaytfuwbstsyffgakkifipcygeu/Build/Products/Debug-iphonesimulator -F/Users/vaibhav/Library/Developer/Xcode/DerivedData/Audioplaying-eaaytfuwbstsyffgakkifipcygeu/Build/Products/Debug-iphonesimulator "-F/Users/vaibhav/Iphone projects/Audioplaying" -filelist /Users/vaibhav/Library/Developer/Xcode/DerivedData/Audioplaying-eaaytfuwbstsyffgakkifipcygeu/Build/Intermediates/Audioplaying.build/Debug-iphonesimulator/Audioplaying.build/Objects-normal/i386/Audioplaying.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=50000 -framework AVFoundation -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/vaibhav/Library/Developer/Xcode/DerivedData/Audioplaying-eaaytfuwbstsyffgakkifipcygeu/Build/Products/Debug-iphonesimulator/Audioplaying.app/Audioplaying

ld: warning: ignoring file /Users/vaibhav/Iphone projects/Audioplaying/AVFoundation.framework/AVFoundation, file was built for unsupported file format which is not the architecture being linked (i386)
Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_AVAudioPlayer", referenced from:
      objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

只需从Build Phases=>Link Binaries With Libraries添加Foundation.frameworkAVFoundation.framework框架,然后尝试即可。

You have somehow created your own broken framework named AVFoundation.framework inside your project. 您已经在项目内部以某种方式创建了自己的损坏的框架,名为AVFoundation.framework The presence of this broken framework is preventing the linker from using the system's AVFoundation framework. 此损坏的框架的存在阻止了链接程序使用系统的AVFoundation框架。

You need to delete /Users/vaibhav/Iphone projects/Audioplaying/AVFoundation.framework and everything in it. 您需要删除/Users/vaibhav/Iphone projects/Audioplaying/AVFoundation.framework及其中的所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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