由CACurrentMediaTime()引起的体系结构i386编译错误的未定义符号 [英] Undefined symbol for architecture i386 compile error caused by CACurrentMediaTime()

查看:111
本文介绍了由CACurrentMediaTime()引起的体系结构i386编译错误的未定义符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm making an iOS application displaying a timer. 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.
     */
}

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

(if I comment out the applicationWillResignActive method body it builds fine)

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

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 /用户/最大/库/ Developer / Xcode / DerivedData / ImpromptuTimer-cbcnsujnixygrxfhtvkovhnpqamb / Build / Products / Debug-iphonesimulator -F / Users / Max / Library / De veloper / Xcode / DerivedData / ImpromptuTimer-cbcnsujnixygrxfhtvkovhnpqamb / Build / Products / Debug-iphonesimulator -filelist /Users/Max/Library/Developer/Xcode/DerivedData/ImpromptuTimer-cbcnsujnixygrxfhtvkovhnpqamb/Build/Intermediates/ImpromptuTimer.build/Debug-iphonesimulator/ImpromptuTimer。建立/对象 - 正常/ I386 / ImpromptuTimer.LinkFileList -mmacosx版本分钟= 10.6 -Xlinker -objc_abi_version -Xlinker 2 -fobjc弧-Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED = 50000 -framework的UIKit -framework基金会-framework CoreGraphics中-o /用户/最大/库/开发商/ Xcode中/ DerivedData / ImpromptuTimer-cbcnsujnixygrxfhtvkovhnpqamb /编译/产品/调试-iphonesimulator / ImpromptuTimer.app / ImpromptuTimer

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-iphonesimulator/ImpromptuTimer.app/ImpromptuTimer

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

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)

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

I think the error is related to not importing the right frameworks, so I tried importing

#import <QuartzCore/CoreAnimation.h>

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

into my my AppDelegate header file, but this did not work either.

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

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

推荐答案

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

You need to link QuartzCore.framework. That's where CACurrentMediaTime comes from: 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

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

编辑:为了澄清,虽然您需要包含/导入QuartzCore是正确的,但您还需要链接它,这是相关的,但不同。请参阅编译和链接

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. See Compiling and Linking

这篇关于由CACurrentMediaTime()引起的体系结构i386编译错误的未定义符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆