Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
484 views
in Technique[技术] by (71.8m points)

objective c - symbol(s) not found in XCode, Cocoa application

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

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 :))

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?

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

Cheers!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...