gpt4 book ai didi

iphone - 链接器错误 OBJC_CLASS_$_AVAudioPlayer”

转载 作者:行者123 更新时间:2023-12-03 20:30:44 24 4
gpt4 key购买 nike

大家好,

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

最佳答案

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

关于iphone - 链接器错误 OBJC_CLASS_$_AVAudioPlayer”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14116945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com