当前位置: 技术问答>linux和unix
《边干边学-Linux内核指导》这本书上的那个“设计自己的驱动程序”的例子拿来编译不知道为什么错???
来源: 互联网 发布时间:2016-07-28
本文导语: (源代码见下面) 书上说:采用下面的命令对vfifo.c进行编译: #gcc -c vfifo.c -D_KERNEL__ -DMODULE -O2 -g -Wall 如果没有出错的话,将会在本目录下生成一个vfifo.o文件。 可是我在redhat 9上编译出错,错误如下: In ...
(源代码见下面)
书上说:采用下面的命令对vfifo.c进行编译:
#gcc -c vfifo.c -D_KERNEL__ -DMODULE -O2 -g -Wall
如果没有出错的话,将会在本目录下生成一个vfifo.o文件。
可是我在redhat 9上编译出错,错误如下:
In file included from /usr/include/linux/fs.h:23,
from vfifo.c:17:
/usr/include/linux/string.h:8:2: warning: #warning Using kernel header in userland!
In file included from vfifo.c:18:
/usr/include/linux/proc_fs.h:70: parse error before "atomic_t"
/usr/include/linux/proc_fs.h:73: parse error before '}' token
/usr/include/linux/proc_fs.h:203: parse error before "void"
In file included from /usr/include/linux/bitops.h:69,
from /usr/include/asm/system.h:7,
from vfifo.c:25:
/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
vfifo.c:27:25: asm/uaccess.h: 没有那个文件或目录
In file included from /usr/include/linux/sched.h:14,
from /usr/include/linux/mm.h:4,
from /usr/include/linux/locks.h:5,
from /usr/include/linux/devfs_fs_kernel.h:6,
from vfifo.c:41:
/usr/include/linux/timex.h:173: field `time' has incomplete type
/usr/include/linux/timex.h:188: confused by earlier errors, bailing out
在Fedora 6上试了也不行。
小弟经验不足,希望能得到大家的指点。
书上说:采用下面的命令对vfifo.c进行编译:
#gcc -c vfifo.c -D_KERNEL__ -DMODULE -O2 -g -Wall
如果没有出错的话,将会在本目录下生成一个vfifo.o文件。
可是我在redhat 9上编译出错,错误如下:
In file included from /usr/include/linux/fs.h:23,
from vfifo.c:17:
/usr/include/linux/string.h:8:2: warning: #warning Using kernel header in userland!
In file included from vfifo.c:18:
/usr/include/linux/proc_fs.h:70: parse error before "atomic_t"
/usr/include/linux/proc_fs.h:73: parse error before '}' token
/usr/include/linux/proc_fs.h:203: parse error before "void"
In file included from /usr/include/linux/bitops.h:69,
from /usr/include/asm/system.h:7,
from vfifo.c:25:
/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
vfifo.c:27:25: asm/uaccess.h: 没有那个文件或目录
In file included from /usr/include/linux/sched.h:14,
from /usr/include/linux/mm.h:4,
from /usr/include/linux/locks.h:5,
from /usr/include/linux/devfs_fs_kernel.h:6,
from vfifo.c:41:
/usr/include/linux/timex.h:173: field `time' has incomplete type
/usr/include/linux/timex.h:188: confused by earlier errors, bailing out
在Fedora 6上试了也不行。
小弟经验不足,希望能得到大家的指点。
|
楼主你安装内核的头文件了吗?驱动程序必须依赖这些的啊,你看我的目录:
[root][~]# ls -al /usr/src/
total 24
drwxrwsr-x 6 root src 4096 2009-02-26 07:43 .
drwxr-xr-x 11 root root 4096 2009-02-26 07:22 ..
drwxr-xr-x 3 root root 4096 2009-02-26 07:43 glibc
drwxr-xr-x 4 root root 4096 2009-02-26 07:40 linux-headers-2.6.26-1-686
drwxr-xr-x 18 root root 4096 2009-02-26 07:40 linux-headers-2.6.26-1-common
drwxr-xr-x 3 root root 4096 2009-02-26 07:40 linux-kbuild-2.6.26
[root][~]# ls -al /usr/src/
total 24
drwxrwsr-x 6 root src 4096 2009-02-26 07:43 .
drwxr-xr-x 11 root root 4096 2009-02-26 07:22 ..
drwxr-xr-x 3 root root 4096 2009-02-26 07:43 glibc
drwxr-xr-x 4 root root 4096 2009-02-26 07:40 linux-headers-2.6.26-1-686
drwxr-xr-x 18 root root 4096 2009-02-26 07:40 linux-headers-2.6.26-1-common
drwxr-xr-x 3 root root 4096 2009-02-26 07:40 linux-kbuild-2.6.26
|
#gcc -c vfifo.c -D_KERNEL__ -DMODULE -O2 -g -Wall
你这里的宏少了个下划线,所以才会提示warning: #warning Using kernel header in userland!。是-D__KERNEL__,而不是-D_KERNEL__
这是一个错误,先更正了再看有没有其他问题
你这里的宏少了个下划线,所以才会提示warning: #warning Using kernel header in userland!。是-D__KERNEL__,而不是-D_KERNEL__
这是一个错误,先更正了再看有没有其他问题