jjzjj

objective-c - Undefined symbol for architecture i386 由 CACurrentMediaTime() 引起的编译错误

coder 2023-07-26 原文

我正在制作一个显示计时器的 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-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)

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

#import <QuartzCore/CoreAnimation.h>

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

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

最佳答案

您需要链接 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

关于objective-c - Undefined symbol for architecture i386 由 CACurrentMediaTime() 引起的编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8549335/

有关objective-c - Undefined symbol for architecture i386 由 CACurrentMediaTime() 引起的编译错误的更多相关文章

随机推荐