gpt4 book ai didi

c++ - Objective-C 的 Xcode 6 上的错误 'Undefined symbols for architecture x86_64 '

转载 作者:太空宇宙 更新时间:2023-11-04 02:47:17 27 4
gpt4 key购买 nike

我开始使用 Xcode 6 学习 Objective C。所以我对此很陌生。我遵循 Web 上的一些教程并尝试一些示例。我正在使用 mac os x 10.9。到目前为止我没有得到这样的错误。我尝试了很多 Objective-C 代码。在这里我附上了我的编码。

主.m

#import <Foundation/Foundation.h>
#import "CarUtilities.h"

int main(int argc, const char * argv[]) {
@autoreleasepool {

NSDictionary *makesAndModels = @{
@"Ford":@[@"Explorer",@"F-150"],
@"Honda":@[@"Accord",@"Civic",@"Pilot"],
@"Nissan":@[@"370Z",@"Altima",@"Versa"],
@"Porsche":@[@"911 Trubo",@"Boxter",@"Cayman S"]

};

NSString *randomCar = CUGetRandomMakeAndModel(makesAndModels);
NSLog(@"Selected a %@",randomCar);
}
return 0;
}


//CarUtilities.m

#导入 #import "CarUtilities.h"

//private function declaration

static id getRandomItemFromArray(NSArray *anArray);

//公共(public)函数实现

NSString *CUGetRandomMake(NSArray *makes){

return getRandomItemFromArray(makes);
}

NSString *CUGetRandomModel(NSArray *models){
return getRandomItemFromArray(models);
}

NSString *CUGetRandomMakeAndModel(NSDictionary *makesAndModels){

NSArray *makes = [makesAndModels allKeys];
NSString *randomMake = CUGetRandomeMake(makes);
NSArray *models = makesAndModels[randomMake];
NSString *randomModel = CUGetRandomeModel(models);

return [randomMake stringByAppendingFormat:@" %@",randomModel];

}

//private function implementation

static id getRandomItemFromArray(NSArray *anArry){

int maximum = (int) [anArry count];
int randomIndex = arc4random_uniform(maximum);

return anArry[randomIndex];

}
CarUtilities.h

#import <Foundation/Foundation.h>

NSString *CUGetRandomeMake(NSArray *makes);
NSString *CUGetRandomeModel(NSArray *models);
NSString *CUGetRandomMakeAndModel(NSDictionary *makesAndModels);

当我尝试运行此代码时出现以下错误。

Ld /Users/samudrjkumara/Library/Developer/Xcode/DerivedData/CarUtilities-govahlvyjxsayfaxlqircwemwocg/Build/Products/Debug/CarUtilities normal x86_64 cd /ObjectiveC/CarUtilities export MACOSX_DEPLOYMENT_TARGET=10.9 /Applications/Xcode6-Beta6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode6-Beta6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -L/Users/samudrjkumara/Library/Developer/Xcode/DerivedData/CarUtilities-govahlvyjxsayfaxlqircwemwocg/Build/Products/Debug -F/Users/samudrjkumara/Library/Developer/Xcode/DerivedData/CarUtilities-govahlvyjxsayfaxlqircwemwocg/Build/Products/Debug -filelist /Users/samudrjkumara/Library/Developer/Xcode/DerivedData/CarUtilities-govahlvyjxsayfaxlqircwemwocg/Build/Intermediates/CarUtilities.build/Debug/CarUtilities.build/Objects-normal/x86_64/CarUtilities.LinkFileList -mmacosx-version-min=10.9 -fobjc-arc -fobjc-link-runtime -Xlinker -dependency_info -Xlinker /Users/samudrjkumara/Library/Developer/Xcode/DerivedData/CarUtilities-govahlvyjxsayfaxlqircwemwocg/Build/Intermediates/CarUtilities.build/Debug/CarUtilities.build/Objects-normal/x86_64/CarUtilities_dependency_info.dat -o /Users/samudrjkumara/Library/Developer/Xcode/DerivedData/CarUtilities-govahlvyjxsayfaxlqircwemwocg/Build/Products/Debug/CarUtilities

体系结构 x86_64 的 undefined symbol : “_CUGetRandomeMake”,引用自: CarUtilities.o 中的 _CUGetRandomMakeAndModel “_CUGetRandomeModel”,引用自: CarUtilities.o 中的 _CUGetRandomMakeAndModel``ld: 找不到体系结构 x86_64 的符号clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

我哪里做错了。由于我是 Xcode 和 Objective C 的新手,请在这方面寻求帮助。

最佳答案

我认为这个问题与项目build设置有关。

在您的目标build设置中检查是否在架构 subview 下:

"Architecture" includes all supported architectures. (including arm64)

"Build active architecture only": NO.

repo 不足,无法添加图片。所以请检查这篇文章中的图片:

Xcode 5 and iOS 7: Architecture and Valid architectures

关于c++ - Objective-C 的 Xcode 6 上的错误 'Undefined symbols for architecture x86_64 ',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25961670/

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