2

大家好,

[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 ,

看到错误后,我已经包含了所有音频框架

 [ 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)
        ]

从堆栈溢出但它仍然对我不起作用..请查看下面的代码,我已经包含了我的 .h 和 .m 文件并建议我一些解决方案

这可能是一个链接器错误,但我已经包含了构建阶段的框架并包含了#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

错误 :

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)
4

2 回答 2

6

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

于 2013-01-02T05:21:58.087 回答
0

您以某种方式创建了自己的损坏框架AVFoundation.framework,并在您的项目中命名。这个损坏的框架的存在阻止了链接器使用系统的AVFoundation框架。

您需要删除/Users/vaibhav/Iphone projects/Audioplaying/AVFoundation.framework其中的所有内容。

于 2013-01-02T06:35:21.540 回答