简体   繁体   English

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

[英]Undefined symbol for architecture i386 compile error caused by CACurrentMediaTime()

I'm making an iOS application displaying a timer. 我正在制作一个显示计时器的iOS应用程序。 I don't think I can keep the timer running after the user presses the home button, so I want to record the time when the user quits the app, and use the time when they reenter the app to update the timer. 在用户按下主页按钮后,我不认为我可以保持计时器运行,所以我想记录用户退出应用程序的时间,并使用他们重新进入应用程序更新计时器的时间。 This is the code I tried: 这是我试过的代码:

- (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.
     */
}

(if I comment out the applicationWillResignActive method body it builds fine) (如果我注释掉applicationWillResignActive方法体,它构建正常)

This is the error I'm getting on compile 这是我在编译时遇到的错误

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/ 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“/开发人员/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-iphonesimulator/ImpromptuTimer.app/ImpromptuTimer 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 /最大/库/开发商/ Xcode中/ DerivedData / ImpromptuTimer-cbcnsujnixygrxfhtvkovhnpqamb /编译/产品/调试-iphonesimulator / ImpromptuTimer.app / ImpromptuTimer

Undefined symbols for architecture i386: "_CACurrentMediaTime", referenced from: -[ImpromptuTimerAppDelegate applicationWillResignActive:] in ImpromptuTimerAppDelegate.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) 架构i386的未定义符号:“_CACurrentMediaTime”,引自: - ImpromptuTimerAppDelegate.o中的[ImpromptuTimerAppDelegate applicationWillResignActive:] ld:未找到架构i386 clang的符号:错误:链接器命令失败,退出代码为1(使用-v to看调用)

I think the error is related to not importing the right frameworks, so I tried importing 我认为错误与不导入正确的框架有关,所以我尝试导入

#import <QuartzCore/CoreAnimation.h>

into my my AppDelegate header file, but this did not work either. 进入我的AppDelegate头文件,但这也无效。

I'm using CACurrentMediaTime() because from what I've read, NSDate is dependent on the network and thus will not give accurate time intervals since it was last used 我正在使用CACurrentMediaTime(),因为根据我的阅读,NSDate依赖于网络,因此无法提供自上次使用以来的准确时间间隔

You need to link QuartzCore.framework. 您需要链接QuartzCore.framework。 That's where CACurrentMediaTime comes from: http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CoreAnimation_functions/Reference/reference.html 这就是CACurrentMediaTime的来源: http//developer.apple.com/library/ios/#documentation/Cocoa/Reference/CoreAnimation_functions/Reference/reference.html

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

edit: To clarify, while you are correct in needing to include/import QuartzCore, you also need to link against it, which is related, but different. 编辑:为了澄清,虽然你需要包含/导入QuartzCore是正确的,你还需要链接它,这是相关的,但不同。 See Compiling and Linking 请参阅编译和链接

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM