当前位置: 技术问答>linux和unix
内核模块,使用全局变量current, 包含#include <linux/kernel.h>编译出错?
来源: 互联网 发布时间:2016-02-12
本文导语: 请大家帮忙: #include 只要包含这个头就出现错误: [root@localhost test_module]# make gcc -Wall -DMODULE -D__KERNEL__ -DLINUX -I/usr/include/ -c hello.c In file included from /usr/include/linux/fs.h:23, from /usr/incl...
请大家帮忙:
#include
只要包含这个头就出现错误:
[root@localhost test_module]# make
gcc -Wall -DMODULE -D__KERNEL__ -DLINUX -I/usr/include/ -c hello.c
In file included from /usr/include/linux/fs.h:23,
from /usr/include/linux/capability.h:17,
from /usr/include/linux/binfmts.h:5,
from /usr/include/linux/sched.h:9,
from hello.c:16:
/usr/include/linux/string.h:8:2: warning: #warning Using kernel header in userland!
In file included from /usr/include/linux/sched.h:14,
from hello.c:16:
/usr/include/linux/timex.h:173: field `time' has incomplete type
In file included from /usr/include/linux/bitops.h:69,
from /usr/include/asm/system.h:7,
from /usr/include/linux/sched.h:16,
from hello.c:16:
/usr/include/asm/bitops.h:327:2: warning: #warning This includefile is not available on all architectures.
/usr/include/asm/bitops.h:328:2: warning: #warning Using kernel headers in userspace: atomicity not guaranteed
In file included from /usr/include/linux/signal.h:4,
from /usr/include/linux/sched.h:25,
from hello.c:16:
/usr/include/asm/signal.h:107: parse error before "sigset_t"
/usr/include/asm/signal.h:110: parse error before '}' token
In file included from /usr/include/linux/sched.h:81,
from hello.c:16:
/usr/include/linux/timer.h:45: parse error before "spinlock_t"
/usr/include/linux/timer.h:53: parse error before '}' token
/usr/include/linux/timer.h:67: parse error before "tvec_base_t"
/usr/include/linux/timer.h:101: parse error before "tvec_bases"
/usr/include/linux/timer.h: In function `init_timer':
/usr/include/linux/timer.h:105: dereferencing pointer to incomplete type
/usr/include/linux/timer.h:105: dereferencing pointer to incomplete type
/usr/include/linux/timer.h:106: dereferencing pointer to incomplete type
/usr/include/linux/timer.h: In function `timer_pending':
/usr/include/linux/timer.h:121: dereferencing pointer to incomplete type
hello.c: In function `init_module':
hello.c:22: warning: implicit declaration of function `printk'
hello.c:37:2: warning: no newline at end of file
make: *** [hello.o] Error 1
怎么回事,谢谢!
#include
只要包含这个头就出现错误:
[root@localhost test_module]# make
gcc -Wall -DMODULE -D__KERNEL__ -DLINUX -I/usr/include/ -c hello.c
In file included from /usr/include/linux/fs.h:23,
from /usr/include/linux/capability.h:17,
from /usr/include/linux/binfmts.h:5,
from /usr/include/linux/sched.h:9,
from hello.c:16:
/usr/include/linux/string.h:8:2: warning: #warning Using kernel header in userland!
In file included from /usr/include/linux/sched.h:14,
from hello.c:16:
/usr/include/linux/timex.h:173: field `time' has incomplete type
In file included from /usr/include/linux/bitops.h:69,
from /usr/include/asm/system.h:7,
from /usr/include/linux/sched.h:16,
from hello.c:16:
/usr/include/asm/bitops.h:327:2: warning: #warning This includefile is not available on all architectures.
/usr/include/asm/bitops.h:328:2: warning: #warning Using kernel headers in userspace: atomicity not guaranteed
In file included from /usr/include/linux/signal.h:4,
from /usr/include/linux/sched.h:25,
from hello.c:16:
/usr/include/asm/signal.h:107: parse error before "sigset_t"
/usr/include/asm/signal.h:110: parse error before '}' token
In file included from /usr/include/linux/sched.h:81,
from hello.c:16:
/usr/include/linux/timer.h:45: parse error before "spinlock_t"
/usr/include/linux/timer.h:53: parse error before '}' token
/usr/include/linux/timer.h:67: parse error before "tvec_base_t"
/usr/include/linux/timer.h:101: parse error before "tvec_bases"
/usr/include/linux/timer.h: In function `init_timer':
/usr/include/linux/timer.h:105: dereferencing pointer to incomplete type
/usr/include/linux/timer.h:105: dereferencing pointer to incomplete type
/usr/include/linux/timer.h:106: dereferencing pointer to incomplete type
/usr/include/linux/timer.h: In function `timer_pending':
/usr/include/linux/timer.h:121: dereferencing pointer to incomplete type
hello.c: In function `init_module':
hello.c:22: warning: implicit declaration of function `printk'
hello.c:37:2: warning: no newline at end of file
make: *** [hello.o] Error 1
怎么回事,谢谢!
|
加入kernel的include路径,-I/usr/src/linux-2.4/include
另外就是系统自带的kernel source最好配置好后make dep
另外就是系统自带的kernel source最好配置好后make dep