You are not logged in.

#1 2023-09-07 11:03:39

arch_fuz
Member
Registered: 2015-01-31
Posts: 34

gcc | header not found

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

#2 2023-09-07 11:49:36

Scimmia
Fellow
Registered: 2012-09-01
Posts: 12,045

Re: gcc | header not found

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

#3 2023-09-07 13:11:49

arch_fuz
Member
Registered: 2015-01-31
Posts: 34

Re: gcc | header not found

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

#4 2023-09-07 13:29:06

seth
Member
Registered: 2012-09-03
Posts: 58,162

Re: gcc | header not found

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

#5 2023-09-07 13:37:18

arch_fuz
Member
Registered: 2015-01-31
Posts: 34

Re: gcc | header not found

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

#6 2023-09-07 14:22:01

seth
Member
Registered: 2012-09-03
Posts: 58,162

Re: gcc | header not found

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

#7 2023-09-07 19:09:20

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 259

Re: gcc | header not found

power_supply.h is an internal kernel API header, you cannot use it from userspace.

Offline

Board footer

Powered by FluxBB