gcc, init.h not found.
I'm trying to do the very first book project that wants to show me how to create a new entry in /proc file system. They gave me a program called hello.c and said that it creates a /proc entry named /proc/hello but I can't get the program to execute. Spent 5-6 hours messing around with it today.
Program looks like this Code:
/** Code:
hello.c:5:10: fatal error: linux/init.h: No such file or directory I also made a Makefile that I found on this forum, it was posted for someone with same problem as me. But it didn't help me. Code:
obj-m += hello.o |
init.h is one of the kernel's built-in headers, the ones used to actually build kernels from source. It isn't included in the exported headers that go into /usr/include/linux. Many distros provide these kernel headers as a separate package, since people need them for building proprietary driver modules. If you can't get that, use the kernel source itself.
|
Look at this Makefile
https://www.tldp.org/LDP/lkmpg/2.4/html/x208.htm A bit old but still work I think |
Quote:
gcc -c -I/usr/src/linux-headers-4.15.0-23-generic/include/ hello.c by searing for init.h and seeing where it was but then it said that <asm/linkage.h> could not be found. I did the same for linkage.h and the amount of errors filled entire terminal. How would I use source exactly? Quote:
Code:
${hello}.o: ${hello}.c rm -rf .o for make command and nothing happens. |
Do you have hello defined somewhere in the Makefile?
Could you post the whole file? I suggested the Makefile from the link as it gives specific options to gcc for compiling a kernel module |
Quote:
Code:
TARGET := hello Code:
gcc-3.0 -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/`uname -r`/build/include -c -o hello.o hello.c |
Also when i input make with Makefile like this
Code:
obj-m += hello.o Code:
make -C /lib/modules/4.15.0-23-generic/build M=/home/illya/Desktop/OS modules |
In the other Makefile, change
Code:
CC := gcc-3.0 Code:
CC := gcc |
Changing to gcc resulted in
Code:
gcc -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/`uname -r`/build/include /usr/src/linux-headers-4.15.0-23/arch/metag/include -c -o hello.o hello.c |
Reviewing kernel.org instruction:
https://www.kernel.org/doc/Documenta...ld/modules.txt Create a file with name: Kbuild Kbuild content: Code:
obj-m := hello.o Makefile content: Code:
KDIR ?= /lib/modules/`uname -r`/build |
Unfortunately that resulted in same errors as in my post No.7.
Could there be something wrong with my system or the program? I'm almost ready to contact the author at this point and ask him directly what I'm supposed to do here. Feels like I could have already been few chapters in but instead I spend time wrestling with this project because the book didn't really teach how to make programs like these from scratch just "type make in terminal and see what happens" so far. Really frustrating when it doesn't work. |
I tried compiling the code, it ended with a hello.ko kernel module, with a warning but no errors
My system runs with kernel 4.4.118 It's possible that kernel header files change from version to another version Try these changes at top of your hello.c file: Code:
#include <linux/init.h> Code:
#include <linux/init.h> |
Code:
#include <linux/init.h> It compiled successfully. Thank you very much for your time. It's beyond my comprehension how that one #include made it successful. Does that means that my uaccess.h was in linux directory and pre-made program assumed it was in asm? I think at one point I tried to do a search for uaccess.h file but it showed so many results that I got somewhat overwhelmed. Again, thanks for your help and time. |
Yes, header files may have changed from the time the program was written in the book and now.
Glad the compilation works now, else I wouldn't see where to go ;) |
All times are GMT -5. The time now is 02:47 AM. |