当前位置: 技术问答>linux和unix
编译出错的问题
来源: 互联网 发布时间:2015-04-22
本文导语: #define __KERNEL__ #define MODULE #include #include #include int init_module(void) { printk("hello,this is the first module!n"); return 0; } void cleanup_module(void) { printk("Leave the first module!n"); } 在RedHat9.0下开终端编译的. ...
#define __KERNEL__
#define MODULE
#include
#include
#include
int init_module(void)
{
printk("hello,this is the first module!n");
return 0;
}
void cleanup_module(void)
{
printk("Leave the first module!n");
}
在RedHat9.0下开终端编译的.
如果我包含进#include sched.h文件
再使用 gcc -c -D__KERNEL__ mhello.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 mhello.c:7:
/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 mhello.c:7:
/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 mhello.c:7:
/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 mhello.c:7:
/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 mhello.c:7:
/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
这是怎么弄的,怎么我包含头文件就出错了呢?我还没干别的呢!
弄清楚就结帖.
#define MODULE
#include
#include
#include
int init_module(void)
{
printk("hello,this is the first module!n");
return 0;
}
void cleanup_module(void)
{
printk("Leave the first module!n");
}
在RedHat9.0下开终端编译的.
如果我包含进#include sched.h文件
再使用 gcc -c -D__KERNEL__ mhello.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 mhello.c:7:
/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 mhello.c:7:
/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 mhello.c:7:
/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 mhello.c:7:
/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 mhello.c:7:
/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
这是怎么弄的,怎么我包含头文件就出错了呢?我还没干别的呢!
弄清楚就结帖.
|
哎呀,这种问题问了很多遍了,用-I来指定目录阿