XCode,Cocoa应用程序中找不到符号 [英] symbol(s) not found in XCode, Cocoa application

查看:233
本文介绍了XCode,Cocoa应用程序中找不到符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管我已经用Java和C(++)进行了一些开发,但是我对Apple的Objective C和XCode还是完全陌生的.

Though I've done some development in Java and and a little in C(++), I'm totally new to Apple's Objective C and XCode.

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

Thus, I'm totally stumped by the following error message:

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

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

It's from a default Cocoa application, with main.m looking like so:

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);
}

(请记住-在这里只是弄湿我的脚...主要是通过拧紧来学习的):)

(Remember - just getting my feet wet here... Learning by screwing up, mainly :))

我猜测IOKit库未正确链接(如果我正确解释了g +​​+的奥秘……),但我不知道如何实际链接它?

I'm guessing the IOKit lib isn't linked correctly (if I interpret the arcane musings of g++ correctly...), but I have no idea how to actually link it?

感谢任何帮助-也提供了有关创建自己的Objective C应用程序的精美教程的任何链接.

Any help appreciated - also any links to nice tutorials on creating your own Objective C apps.

干杯!

推荐答案

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

Have you added IOKit as a linked framework? In XCode, expand Targets, then your target (BatteryApp I would guess), then Link Binary With Libraries. If you don't see IOKit, you'll want to add it.

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

Up at the top of the tree, look for the Frameworks directory. Right-click, Add, Existing Frameworks. Browse to /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/(appropriate SDK)/System/Library/Frameworks/IOKit.framework, and click OK.

即使您添加了框架的模拟器版本,但我相信XCode会在您在模拟器和Device目标之间切换时自动切换库搜索路径,所以我认为还可以.

Even though you added the simulator version of the framework, it is my belief that XCode will automatically switch the library search path as you switch between the Simulator and Device targets, so I think it's OK.

这篇关于XCode,Cocoa应用程序中找不到符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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