Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 3290  / 12 Months ago, tue, may 30, 2023, 11:18:55

I am new to Ubuntu and I am trying to compile a small program. I have a Makefile and raw1394.c file in a folder raw1394.



when I run a make command it should produce raw1394.ko file but I am getting nothing in when I run make command.



I also tried to compile raw1394.c file with gcc but it is giving me following error.



raw1394.c:1:26: fatal error: linux/module.h: No such file or directory
compilation terminated


could you please guide me how can I solve this problem.



here is my Makefie



obj-m += raw1394.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean


and here is my raw1394.c file



#include <linux/module.h>
#include <linux/kernel.h>

int init_module(void)
{
printk(KERN_INFO "Loaded dummy raw1394 module
");
return 0;
}

More From » 12.04

 Answers
6

GCC gives the error because it cannot find the header file(s) you include. You should:




  1. check whether the path is not in the raw1394.c folder, because then you need to use quotes in stead of <>: so #include "linux/module.h" (this might be the case if you do not want to use your own kernel's header files)

  2. Check your compiler path whether there is a file named linux with the header files in it. You're probably missing the Linux headers.



Secondly, makefiles are used for automating the compilation process (since this often involves multiple instructions and/or different instructions for different targets). But you will still need the correct gcc command(s) in your makefile. So your (basic) makefile should look like this (a lot of extensions and flexibility can be added to it, read more about makefiles if you want to do this):



CC=gcc
CFLAGS=-Wall -c

raw: raw1394.c
TAB $(CC) $(CFLAGS) raw1394/raw1394.c

all:
clean:
TAB rm -rf raw1394/*.o


Note that specific intendations are used in Makefiles. Therefore I put TAB in the code where there should actually be a tab (multiple spaces will NOT work).



Typing make raw in the correct directory on the command line will automatically execute target raw in the Makefile.


[#28389] Tuesday, May 30, 2023, 12 Months  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
oreera

Total Points: 472
Total Questions: 121
Total Answers: 116

Location: Mayotte
Member since Thu, Dec 17, 2020
3 Years ago
;