You are not logged in.
Pages: 1
Hi.
Guess it is kind of stupid question, but I could not make it to include the header file needed...
I installed linux-headers. The package installed the file here:
/usr/lib/modules/6.4.12-arch1-1/build/include/linux/power_supply.h
I have this in my source file:
#include <linux/power_supply.h>
This is what I get:
gcc battery_status.c -o battery_status
battery_status.c:1:10: schwerwiegender Fehler: linux/power_supply.h: File not found
1 | #include <linux/power_supply.h>
| ^~~~~~~~~~~~~~~~~~~~~~
What am I doing wrong?
Thanks, _fuz
Offline
You have to give it the include path if it's not in the default (like /usr/include/). Add -I/usr/lib/modules/6.4.12-arch1-1/build/include/ to your gcc command.
Offline
Many thanks, that worked.
Now I have an unresolved dependency in compiler.h. The file /usr/include/asm/rwonce.h is not existing in asm/, I looked it up:
gcc -I/usr/lib/modules/6.4.12-arch1-1/build/include/ battery_status.c -o battery_status
In Datei, eingebunden von /usr/lib/modules/6.4.12-arch1-1/build/include/linux/dev_printk.h:14,
von /usr/lib/modules/6.4.12-arch1-1/build/include/linux/device.h:15,
von /usr/lib/modules/6.4.12-arch1-1/build/include/linux/power_supply.h:15,
von battery_status.c:1:
/usr/lib/modules/6.4.12-arch1-1/build/include/linux/compiler.h:246:10: schwerwiegender Fehler: asm/rwonce.h: Datei oder Verzeichnis nicht gefunden
246 | #include <asm/rwonce.h>
| ^~~~~~~~~~~~~~
What do you suggest I should do? In asm-generic/ there is such file included...
Thanks,
_fuz
Offline
You'll find it in usr/lib/modules/6.4.12-arch1-1/build/arch/x86/include/generated/asm/rwonce.h
Since this is a glaring https://en.wikipedia.org/wiki/XY_problem - what are you actually trying to build there?
You're not compiling a kernel module you wrote yourself?
Also please use [code][/code] tags. Edit your post in this regard.
Offline
I want to build a small app which is getting the battery status and display it to me. Besides that I have some time now to play around using linux an c. This is what I got to get the status:
#include <linux/power_supply.h>
int main(int argc, char* argv[])
{
char name[]= "CMB1";
int result = 0;
struct power_supply *psy = power_supply_get_by_name(name);
union power_supply_propval chargenow, chargefull;
result = psy->get_property(psy,POWER_SUPPLY_PROP_CHARGE_NOW,&chargenow);
if(!result) {
printk(KERN_INFO "The charge level is %d\n",chargenow.intval);
}
result = psy->get_property(psy,POWER_SUPPLY_PROP_CHARGE_FULL,&chargefull);
if(!result) {
printk(KERN_INFO "The charge level is %d\n",chargefull.intval);
}
}
Offline
I want to build a small app which is getting the battery status and display it to me.
You mean like acpi?
Do you intentionally not use the /sys/class/power_supply/ kernel filesystem for this?
I have some time now to play around using linux an c.
linux like teh kernel or just the OS? Your described task does not sound like you're actually trying to write kernel code, so don't use the kernel headers but either the filesystem exposed interface or the general API in /usr/include/linux
Offline
power_supply.h is an internal kernel API header, you cannot use it from userspace.
Offline
Pages: 1