在XCode,Cocoa应用程序中找不到的符号

5 objective-c

虽然我已经完成了一些Java开发和一些C(++)开发,但我完全不熟悉Apple的Objective C和XCode.

因此,我完全被以下错误消息困扰:

Building target “BatteryApp” of project “BatteryApp” with configuration “Debug” — (1 error)
        cd /Users/soren/Documents/BatteryApp
    setenv MACOSX_DEPLOYMENT_TARGET 10.5
    /Developer/usr/bin/gcc-4.0 -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk -L/Users/soren/Documents/BatteryApp/build/Debug -F/Users/soren/Documents/BatteryApp/build/Debug -filelist /Users/soren/Documents/BatteryApp/build/BatteryApp.build/Debug/BatteryApp.build/Objects-normal/i386/BatteryApp.LinkFileList -mmacosx-version-min=10.5 -framework Cocoa -o /Users/soren/Documents/BatteryApp/build/Debug/BatteryApp.app/Contents/MacOS/BatteryApp
Undefined symbols:
  "_IOPSCopyPowerSourcesList", referenced from:
      _main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
          "_IOPSCopyPowerSourcesList", referenced from:
              _main in main.o
        ld: symbol(s) not found
        collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

它来自默认的Cocoa应用程序,main.m看起来像这样:

import <Cocoa/Cocoa.h>
import <IOKit/ps/IOPowerSources.h>

int main(int argc, char *argv[])
{
    CFTypeRef powerInfo;
    IOPSCopyPowerSourcesList(powerInfo);
    NSLog(@"Foo");
    //return NSApplicationMain(argc,  (const char **) argv);
}
Run Code Online (Sandbox Code Playgroud)

(记住 - 只是让我的脚湿透了......通过搞砸来学习,主要是:))

我猜测IOKit lib没有正确链接(如果我正确地解释了g +​​+的神秘冥想......),但我不知道如何实际链接它?

任何帮助表示赞赏 - 也有关于创建自己的Objective C应用程序的精彩教程的任何链接.

干杯!

Dan*_*sky 7

您是否已将IOKit添加为链接框架?在XCode中,展开Targets,然后是你的目标(我会猜测BatteryApp),然后是Link Binary With Libraries.如果您没有看到IOKit,则需要添加它.

在树的顶部,查找Frameworks目录.右键单击,添加,现有框架.浏览到/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/(适当的SDK)/System/Library/Frameworks/IOKit.framework,然后单击OK.

即使你添加了框架的模拟器版本,我相信当你在模拟器和设备目标之间切换时,XCode会自动切换库搜索路径,所以我认为没关系.