LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   module compilation fails (https://www.linuxquestions.org/questions/programming-9/module-compilation-fails-418706/)

taux 02-23-2006 07:36 AM

module compilation fails
 
Hi all,

I tried to compile a simple module on linux and saw a bunch of errors:

Module code:

1 #define MODULE
2 #include <linux/module.h>
3
4 int init_module(void) { printk("<1>Hello, world\n"); return 0; }
5 void cleanup_module(void) { printk("<1>Goodbye cruel world\n"); }

Errors:

"gcc -c hello.c"

In file included from /usr/include/linux/sched.h:16,
from /usr/include/linux/module.h:9,
from hello.c:2:
/usr/include/linux/signal.h:2:2: warning: #warning "You should include <signal.h>. This time I will do it for you."
In file included from /usr/include/linux/resource.h:4,
from /usr/include/linux/sched.h:79,
from /usr/include/linux/module.h:9,
from hello.c:2:
/usr/include/linux/time.h:9: error: redefinition of ‘struct timespec’
/usr/include/linux/time.h:15: error: redefinition of ‘struct timeval’
/usr/include/linux/time.h:20: error: redefinition of ‘struct timezone’
/usr/include/linux/time.h:47: error: redefinition of ‘struct itimerval’
In file included from hello.c:2:
/usr/include/linux/module.h:41: error: field ‘attr’ has incomplete type
/usr/include/linux/module.h:49: error: field ‘kobj’ has incomplete type

I am running Ubuntu 5.10 "Breezy Badger", on kernel 2.6.14.1

Maybe anyone knows where the problem is?

Thanx a lot.

taux 02-23-2006 04:50 PM

solved
 
Allready solved the problem. 2.6 kernel seems to have specialised module compilation. You have to write such makefile:

Code:

obj-m := hello.o
KDIR := /usr/src/linux/linux-2.6.14.1/
PWD := $(shell pwd)
default:
  $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules



All times are GMT -5. The time now is 11:59 PM.