XCode:Apple Mach-O 链接器错误与新的 iOS 6 ABAddressBook 函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14308517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:30:52  来源:igfitidea点击:

XCode: Apple Mach-O Linker Error with New iOS 6 ABAddressBook Functions

iphoneiosxcodeios6abaddressbook

提问by JRoss

I am running Xcode 4.2 with an imported IOS 6 SDK (older Mac incapable of running XCode 4.5). My app is configured with an iOS Deployment Target of 4.3, a Base SDK of 6.0, and Architectures of armv7 only.

我正在使用导入的 IOS 6 SDK 运行 Xcode 4.2(较旧的 Mac 无法运行 XCode 4.5)。我的应用程序配置了 4.3 的 iOS 部署目标、6.0 的基本 SDK 和仅 armv7 的架构。

I am trying to update my previously working app to request permission to access a user's address book, which is now a requirement for iOS 6 (using the new iOS 6 functions). Unfortunately, I am receiving the following Apple Mach-O Linker Error:

我正在尝试更新我以前工作的应用程序以请求访问用户地址簿的权限,这现在是 iOS 6 的要求(使用新的 iOS 6 功能)。不幸的是,我收到以下 Apple Mach-O 链接器错误:

Ld /Users/Blake/Library/Developer/Xcode/DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/Debug-iphoneos/MyApp.app/MyApp normal armv7 cd /Users/Blake/Desktop/MyApp/MyApp setenv IPHONEOS_DEPLOYMENT_TARGET 4.3 setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -L/Users/Blake/Library/Developer/Xcode/DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/Debug-iphoneos -L/Users/Blake/Desktop/MyApp/MyApp/../../../Downloads/ScannerKit-Latest/Demo/Libraries/ScannerKit -F/Users/Blake/Library/Developer/Xcode/DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/Debug-iphoneos -filelist /Users/Blake/Library/Developer/Xcode/DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Intermediates/MyApp.build/Debug-iphoneos/MyApp.build/Objects-normal/armv7/MyApp.LinkFileList -dead_strip -all_load -lstdc++ -fobjc-arc -miphoneos-version-min=4.3 -framework AddressBook -framework AddressBookUI -framework UIKit -framework Foundation -framework CoreGraphics -lScannerKit -framework AVFoundation -framework CoreMedia -framework SystemConfiguration -framework CoreVideo -liconv -framework AudioToolbox -framework QuartzCore -o /Users/Blake/Library/Developer/Xcode/DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/Debug-iphoneos/MyApp.app/MyApp

Undefined symbols for architecture armv7:
"_ABAddressBookRequestAccessWithCompletion", referenced from: -[ServerConnect parserDidEndDocument:] in ServerConnect.o "_ABAddressBookGetAuthorizationStatus", referenced from: -[ServerConnect parserDidEndDocument:] in ServerConnect.o "_ABAddressBookCreateWithOptions", referenced from: -[ServerConnect parserDidEndDocument:] in ServerConnect.o ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Ld /Users/Blake/Library/Developer/Xcode/DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/Debug-iphoneos/MyApp.app/MyApp normal armv7 cd /Users/Blake/Desktop/MyApp/MyApp setenv IPHONEOS_DEPLOYMENT_PATH3 /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Developer/Platforms/iPhoneOS.platform/Developer/usr /bin/clang -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -L/Users/Blake/Library/Developer/Xcode/DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/调试-iphoneos -L/Users/Blake/Desktop/MyApp/MyApp/../../../Downloads/ScannerKit-Latest/Demo/Libraries/ScannerKit -F/Users/Blake/Library/Developer/Xcode/DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/Debug-iphoneos -filelist /Users/Blake/Library/Developer/Xcode /DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Intermediates/MyApp.build/Debug-iphoneos/MyApp.build/Objects-normal/armv7/MyApp.LinkFileList -dead_strip -all_load -lstdc++ -fobjc-arc -miphoneos-version-min=4 -framework AddressBook -framework AddressBookUI -framework UIKit -framework Foundation -framework CoreGraphics -lScannerKit -framework AVFoundation -framework CoreMedia -framework SystemConfiguration -framework CoreVideo -liconv -framework AudioToolbox -framework QuartzCore -o /Users/Blake/Library/Developer/Xcode/ DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/Debug-iphoneos/MyApp.app/MyApp应用程序/我的应用程序应用程序/我的应用程序build/Objects-normal/armv7/MyApp.LinkFileList -dead_strip -all_load -lstdc++ -fobjc-arc -miphoneos-version-min=4.3 -framework AddressBook -framework AddressBookUI -framework UIKit -framework Foundation -framework CoreGraphics -lScannerKit -framework AVFoundation - framework CoreMedia -framework SystemConfiguration -framework CoreVideo -liconv -framework AudioToolbox -framework QuartzCore -o /Users/Blake/Library/Developer/Xcode/DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/Debug-iphoneos/MyApp.app/MyAppbuild/Objects-normal/armv7/MyApp.LinkFileList -dead_strip -all_load -lstdc++ -fobjc-arc -miphoneos-version-min=4.3 -framework AddressBook -framework AddressBookUI -framework UIKit -framework Foundation -framework CoreGraphics -lScannerKit -framework AVFoundation - framework CoreMedia -framework SystemConfiguration -framework CoreVideo -liconv -framework AudioToolbox -framework QuartzCore -o /Users/Blake/Library/Developer/Xcode/DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/Debug-iphoneos/MyApp.app/MyApp3 -framework AddressBook -framework AddressBookUI -framework UIKit -framework Foundation -framework CoreGraphics -lScannerKit -framework AVFoundation -framework CoreMedia -framework SystemConfiguration -framework CoreVideo -liconv -framework AudioToolbox -framework QuartzCore -o /Users/Blake/Library/Developer/Xcode /DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/Debug-iphoneos/MyApp.app/MyApp3 -framework AddressBook -framework AddressBookUI -framework UIKit -framework Foundation -framework CoreGraphics -lScannerKit -framework AVFoundation -framework CoreMedia -framework SystemConfiguration -framework CoreVideo -liconv -framework AudioToolbox -framework QuartzCore -o /Users/Blake/Library/Developer/Xcode /DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/Debug-iphoneos/MyApp.app/MyApp

架构 armv7 的未定义符号:
_ABAddressBookRequestAccessWithCompletion”,引用自:ServerConnect.o 中的 -[ServerConnect parserDidEndDocument:] “ _ABAddressBookGetAuthorizationStatus”,引用自:ServerConnect.o 中的 -[ServerConnect parserDidEndDocument:] “ _ABAddressBookCreateWithOptions”,引用自:-[ServerConnectServerConnect parserDidEndDocument:] in ServerConnect.o ld: 找不到架构 armv7 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

My best guess is that XCode 4.2 is looking in the iPhoneOS5.0.sdk instead of my iPhoneOS6.0.sdk for architecture armv7. However, I am unable to see where I can fix this problem. Has anyone else encountered this problem before? Thanks for any help in advance!

我最好的猜测是 XCode 4.2 正在寻找 iPhoneOS5.0.sdk 而不是我的 iPhoneOS6.0.sdk 架构 armv7。但是,我看不到哪里可以解决这个问题。有没有其他人遇到过这个问题?提前感谢您的任何帮助!

My Code (for Reference):

我的代码(供参考):

// Fetch the address book 
//Check if we are using iOS6
if ([self isABAddressBookCreateWithOptionsAvailable]) {
        ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);

        if (ABAddressBookGetAuthorizationStatus() == 0) {
            ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
                // First time access has been granted
                [self searchForPersonInAddressBook:addressBook withName:fullName];
            });
        }
        else if (ABAddressBookGetAuthorizationStatus() == 3) {
            // The user has previously given access
            [self searchForPersonInAddressBook:addressBook withName:fullName];
        }
        else {
            // The user has previously denied access
            UIAlertView *deniedAccess=[[UIAlertView alloc] initWithTitle:@"Unable to Access Address Book" message:@"Change App Privacy Settings" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [deniedAccess show];
        }
    }
    //If using iOS 4/5
    else {
        ABAddressBookRef addressBook = ABAddressBookCreate();
        [self searchForPersonInAddressBook:addressBook withName:fullName];
    }
}

- (void)searchForPersonInAddressBook:(ABAddressBookRef )ab
                withName:(NSString *)fn
{
// Search for the person in the address book
CFArrayRef person = ABAddressBookCopyPeopleWithName(ab, (__bridge CFStringRef)fn);
// Display message if person not found in the address book 
if ((person != nil) && (CFArrayGetCount(person) == 0)) {
    // Show an alert if name is not in Contacts
    UIAlertView *saveContact=[[UIAlertView alloc] initWithTitle:@"Save New Contact to iPhone?" message:fn delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Save!", nil];
    saveContact.tag = 2;
    [saveContact show];
}
}

- (BOOL)isABAddressBookCreateWithOptionsAvailable
{
     return &ABAddressBookCreateWithOptions != NULL;
}

回答by Valentin Radu

That's the type of error you usually get if you don't link the framework to your project. So you probably imported your headers (thus no compile time error) however, you didn't add AddressBook.frameworkfrom TargetName->Build Phases->Link Binary With Libraries

如果您不将框架链接到您的项目,通常会遇到这种类型的错误。所以你可能导入了你的头文件(因此没有编译时错误)但是,你没有AddressBook.frameworkTargetName->Build Phases->Link Binary With Libraries

回答by JRoss

I solved my problem through weak linking the AddressBook Frameworks in the "Link Binary with Libraries" Section of my Target's Build Phases Settings ("Optional" instead of "Required").

我通过在目标的构建阶段设置的“链接二进制与库”部分(“可选”而不是“必需”)中弱链接地址簿框架解决了我的问题。

Also, I believe there is an XCode4.2 bug in which it duplicates the device destination. For some reason, after choosing the duplicate, my app was able to compile (See the following link: How to access weak linked framework in iOS?).

另外,我相信有一个 XCode4.2 错误,它复制了设备目标。出于某种原因,选择副本后,我的应用程序能够编译(请参阅以下链接:如何访问 iOS 中的弱链接框架?)。