由CACurrentMediaTime()引起的体系结构i386编译错误的未定义符号

时间:2011-12-18 02:01:35

标签: objective-c ios timer core-animation

我正在制作一个显示计时器的iOS应用程序。在用户按下主页按钮后,我不认为我可以保持计时器运行,所以我想记录用户退出应用程序的时间,并使用他们重新进入应用程序更新计时器的时间。这是我试过的代码:

- (void)applicationWillResignActive:(UIApplication *)application
{
    double currentTime = CACurrentMediaTime(); 
    NSLog(@"%g", currentTime);
    /*
     Sent when the application is about to move from active to inactive state. This can     occur for certain types of temporary interruptions (such as an incoming phone call or SMS     message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}

(如果我注释掉applicationWillResignActive方法体,那么它构建正常)

这是我在编译时遇到的错误

  

Ld /Users/Max/Library/Developer/Xcode/DerivedData/ImpromptuTimer-cbcnsujnixygrxfhtvkovhnpqamb/Build/Products/Debug-iphonesimulator/ImpromptuTimer.app/ImpromptuTimer normal i386           cd / Users / Max / Developer / ImpromptuTimer           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 / Max / Library / Developer / Xcode / DerivedData / ImpromptuTimer-cbcnsujnixygrxfhtvkovhnpqamb / Build / Products / Debug-iphonesimulator -F / Users / Max / Library / Developer / Xcode / DerivedData / ImpromptuTimer-cbcnsujnixygrxfhtvkovhnpqamb / Build / Products / Debug-iphonesimulator -filelist / Users / Max / Library / Developer / Xcode / DerivedData / ImpromptuTimer-cbcnsujnixygrxfhtvkovhnpqamb / Build / Intermediates / ImpromptuTimer.build / Debug-iphonesimulator / ImpromptuTimer.build / Objects-normal / i386 / ImpromptuTimer.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 UIKit -framework Foundation -framework CoreGraphics -o / Users / Max / Library / Developer / Xcode / DerivedData / ImpromptuTimer-cbcnsujnixygrxfhtvkovhnpqamb / Build / Products / Debug-iphonesim ulator / ImpromptuTimer.app / ImpromptuTimer

     

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

我认为错误与不导入正确的框架有关,所以我尝试导入

#import <QuartzCore/CoreAnimation.h>

进入我的AppDelegate头文件,但这也不起作用。

我正在使用CACurrentMediaTime(),因为根据我的阅读,NSDate依赖于网络,因此自上次使用以来不会给出准确的时间间隔

2 个答案:

答案 0 :(得分:31)

您需要链接QuartzCore.framework。 这就是CACurrentMediaTime的来源:http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CoreAnimation_functions/Reference/reference.html

请参阅此文档,了解如何添加框架: https://developer.apple.com/library/ios/#recipes/xcode_help-project_editor/Articles/AddingaLibrarytoaTarget.html#//apple_ref/doc/uid/TP40010155-CH17-SW1

编辑:为了澄清,虽然你需要包含/导入QuartzCore是正确的,但你还需要链接它,这是相关的,但不同。见Compiling and Linking

答案 1 :(得分:4)

简单地添加QuartzCore.framework解决了它。