Help needed Using C File In Project, iPhone
I am new to all this, but here goes:
There is an apple file that I would like to use parts of for my app. It is called BatteryTimeRemaining.c.
http://www.opensource.apple.com/source/PowerManagement/PowerManagement-21开发者_Go百科1/pmconfigd/BatteryTimeRemaining.c
I want to be able to use some of the calculations in it, the problem being I don't to know how to add and use it properly. I get countless errors e.g. undeclared: first use of this function.
Do I need to add all the header files which are included in the .c file? Do I compile it and then add?
Many thanks, Stuart
Yeh you would need to include all the header files mentioned in BatteryTimeRemaining.c. So all of these files...
#include <syslog.h>
#include <unistd.h>
#include <stdlib.h>
#include <notify.h>
#include <mach/mach.h>
#include <mach/mach_port.h>
#include <servers/bootstrap.h>
#include <asl.h>
#include "powermanagementServer.h" // mig generated
#include "BatteryTimeRemaining.h"
#include "SetActive.h"
#include "PrivateLib.h"
All the triangle bracket includes should be system include files and so should be on your system already. The quoted include files though are likely part of that project you are retrieving BatteryTimeRemaining.c from. You would need to copy them out of that project to your own project.
Likely its easier to copy out the functions you want and paste them into your own code base. No doubt you'll have some dependency issues but its probably easier to get one or two functions building on your system then the whole file. It's pretty long.
What function did you want to use exactly out of BatteryTimeRemaining.c?
Try adding just
#import "BatteryTimeRemaining.h"
to the file you want to use these functions in. It might be enough..
Unfortunately, most of the functions contained in this file are mac-specific, hence my problems using some of it's contents.
精彩评论