Character (s) not found in Xcode, Cocoa

Although I did some Java development and a bit of C (++), I am completely new to Apple Objective-C and Xcode.

Thus, I am completely puzzled 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 

This is from the Cocoa default application, with main.m looking like this:

 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 wet my legs here ... Learning to spin, mostly :))

I assume that the IOKit library is not linked correctly (if I correctly interpret the secret thoughts of g ++ ...), but I have no idea how to actually link it?

Any help is appreciated - also any links to good tutorials on building your own Objective-C applications.

Hooray!

+4
source share
3 answers

Have you added IOKit as a related structure? In Xcode, expand Targets, then your target (BatteryApp, I would guess), and then Link Binary With Libraries. If you do not see IOKit, you want to add it.

At the top of the tree, locate the Framework directory. Right-click, Add, Existing Frames. Go to /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/(Adobe SDK) /System/Library/Frameworks/IOKit.framework and click OK.

Despite the fact that you have added a version of the framework simulator, I believe that Xcode will automatically switch the library search path when switching between the target parameters of Simulator and Device, so I think this is normal.

+7
source

I believe that you are right in thinking that the IOKit structure is not connected correctly. Here you can see:

  • Expand the Goals group in your groups and files tree and double-click the goal that IOKit needs. (Or right-click and select "Get Information"). The target dashboard is displayed.
  • The first tab of the dashboard is where we should be. The bottom half of the tab is a list of linked libraries. IOKit is probably not on this list, so click the plus button in the lower left.
  • Scroll down a bit until you see IOKit.framework. Select it and click "Add." This will add IOKit to your infrastructure and link it to the goal.

If you have already added the IOKit framework to your project, you just need to verify that it is part of the "Link to Binary Files with Libraries" phase of the appropriate purpose. (Target group> expand your target> Binary link with libraries). If this is not the case in your project, then you can either follow the steps described above or simply drag and drop the framework from where it is in your groups and file tree.

+4
source

I am not an expert in Xcode / cocoa -touch myself, but according to this link , it seems that the IOKit structure isn’t accessible to the general public.

In official docs, I found a quote that described IOKit as such: β€œContains the interfaces used by the device. Do not include this structure directly.” Therefore, in the end, my desire to access this IOKit information was thwarted. For some reason, Apple decided to list it as a public structure, but the reality is that it is not.

0
source

All Articles