再问debian内核源码的问题!郁闷死了

软件和网站开发以及相关技术探讨
回复
NeptuneStar
帖子: 20
注册时间: 2005-08-30 13:10
送出感谢: 0
接收感谢: 0
联系:

再问debian内核源码的问题!郁闷死了

#1

帖子 NeptuneStar » 2005-09-05 22:56

我在各位的指导下,下了kernel-source-2.4.27,kernel-headers-2.4.27-2-386
结果在/usr/src下有了kernel-source-2.4.27,kernel-headers-2.4.27-2,kernel- headers-2.4.27-2-386几个文件夹,为什么会有两个kernel-headers呢?后来我写了个简单的模块程序:
#include <linux/module.h>
int init_module(void)
{
printk("Hello,world!\n");
return 0;
}
void cleanup_module(void)
{
printk("Bye!\n");
}
它的makefile如下:
CC=g++
INCLUDE=-I/usr/src/kernel-source-2.4.27/include/
CFLAG=-D__KERNEL__ -DMODULE -Wall -O2 -g
hello.o:hello.c
$(CC) $(INCLUDE) $(CFLAG) -c hello.c

结果出了很多错:

g++ -I/usr/src/kernel-source-2.4.27/include/ -D__KERNEL__ -DMODULE -Wall -O2 -g -c hello.c
In file included from /usr/include/asm/system.h:5,
from /usr/src/kernel-source-2.4.27/include/linux/spinlock.h:6,
from /usr/src/kernel-source-2.4.27/include/linux/module.h:12,
from hello.c:1:
/usr/src/kernel-source-2.4.27/include/linux/kernel.h:75: error: type specifier
omitted for parameter `size_t'
/usr/src/kernel-source-2.4.27/include/linux/kernel.h:75: error: parse error
before `,' token
/usr/src/kernel-source-2.4.27/include/linux/kernel.h:77: error: type specifier
omitted for parameter `size_t'
/usr/src/kernel-source-2.4.27/include/linux/kernel.h:77: error: parse error
before `,' token
In file included from /usr/src/kernel-source-2.4.27/include/linux/spinlock.h:6,
from /usr/src/kernel-source-2.4.27/include/linux/module.h:12,
from hello.c:1:
/usr/include/asm/system.h:246: error: parse error before `new'
/usr/include/asm/system.h: In function `long unsigned int __cmpxchg(...)':
/usr/include/asm/system.h:249: error: `size' undeclared (first use this
function)
/usr/include/asm/system.h:249: error: (Each undeclared identifier is reported
only once for each function it appears in.)
/usr/include/asm/system.h:253: error: parse error before `)' token
/usr/include/asm/system.h:259: error: parse error before `)' token
/usr/include/asm/system.h:265: error: parse error before `)' token
/usr/include/asm/system.h:269: error: `old' undeclared (first use this
function)
In file included from /usr/src/kernel-source-2.4.27/include/linux/module.h:13,
from hello.c:1:
/usr/src/kernel-source-2.4.27/include/linux/list.h: At global scope:
/usr/src/kernel-source-2.4.27/include/linux/list.h:37: error: parse error
before `new'
/usr/src/kernel-source-2.4.27/include/linux/list.h: In function `void
__list_add(...)':
/usr/src/kernel-source-2.4.27/include/linux/list.h:41: error: `next' undeclared
(first use this function)
/usr/src/kernel-source-2.4.27/include/linux/list.h:41: error: parse error
before `;' token
/usr/src/kernel-source-2.4.27/include/linux/list.h:44: error: `prev' undeclared
(first use this function)
/usr/src/kernel-source-2.4.27/include/linux/list.h:44: error: parse error
before `;' token
/usr/src/kernel-source-2.4.27/include/linux/list.h: At global scope:
/usr/src/kernel-source-2.4.27/include/linux/list.h:55: error: parse error
before `new'
/usr/src/kernel-source-2.4.27/include/linux/list.h: In function `void
list_add(...)':
/usr/src/kernel-source-2.4.27/include/linux/list.h:57: error: parse error
before `,' token
/usr/src/kernel-source-2.4.27/include/linux/list.h: At global scope:
/usr/src/kernel-source-2.4.27/include/linux/list.h:68: error: parse error
before `new'
/usr/src/kernel-source-2.4.27/include/linux/list.h: In function `void
list_add_tail(...)':
/usr/src/kernel-source-2.4.27/include/linux/list.h:70: error: parse error
before `,' token
/usr/src/kernel-source-2.4.27/include/linux/list.h: In function `void
list_del(list_head*)':
/usr/src/kernel-source-2.4.27/include/linux/list.h:94: error: invalid
conversion from `void*' to `list_head*'
/usr/src/kernel-source-2.4.27/include/linux/list.h:95: error: invalid
conversion from `void*' to `list_head*'
make: *** [hello.o] 错误 1
于是我把
INCLUDE=-I/usr/src/kernel-source-2.4.27/include/
改成:-I/usr/src/kernel-headers-2.4.27-2-386/include/和
-I/usr/src/kernel-headers-2.4.27-2/include/
都不行,为什么?
又下了 kernel-patch-debian-2.4.27 kernel-tree-2.4.27两个包,结果/usr/src下只有kernel-patch,后面的kernel-tree不知道那去了, debian下的内核源代码究竟是哪个啊?感觉好乱啊,不想redhat那么清晰!
求大虾们指点啊。。。
emacsnw
帖子: 5
注册时间: 2005-09-06 16:48
送出感谢: 0
接收感谢: 0

Re: 再问debian内核源码的问题!郁闷死了

#2

帖子 emacsnw » 2005-09-06 17:03

CC=gcc

NeptuneStar 写了:我在各位的指导下,下了kernel-source-2.4.27,kernel-headers-2.4.27-2-386
结果在/usr/src下有了kernel-source-2.4.27,kernel-headers-2.4.27-2,kernel- headers-2.4.27-2-386几个文件夹,为什么会有两个kernel-headers呢?后来我写了个简单的模块程序:
#include <linux/module.h>
int init_module(void)
{
printk("Hello,world!\n");
return 0;
}
void cleanup_module(void)
{
printk("Bye!\n");
}
它的makefile如下:
CC=g++
INCLUDE=-I/usr/src/kernel-source-2.4.27/include/
CFLAG=-D__KERNEL__ -DMODULE -Wall -O2 -g
hello.o:hello.c
$(CC) $(INCLUDE) $(CFLAG) -c hello.c

结果出了很多错:

g++ -I/usr/src/kernel-source-2.4.27/include/ -D__KERNEL__ -DMODULE -Wall -O2 -g -c hello.c
In file included from /usr/include/asm/system.h:5,
from /usr/src/kernel-source-2.4.27/include/linux/spinlock.h:6,
from /usr/src/kernel-source-2.4.27/include/linux/module.h:12,
from hello.c:1:
/usr/src/kernel-source-2.4.27/include/linux/kernel.h:75: error: type specifier
omitted for parameter `size_t'
/usr/src/kernel-source-2.4.27/include/linux/kernel.h:75: error: parse error
before `,' token
/usr/src/kernel-source-2.4.27/include/linux/kernel.h:77: error: type specifier
omitted for parameter `size_t'
/usr/src/kernel-source-2.4.27/include/linux/kernel.h:77: error: parse error
before `,' token
In file included from /usr/src/kernel-source-2.4.27/include/linux/spinlock.h:6,
from /usr/src/kernel-source-2.4.27/include/linux/module.h:12,
from hello.c:1:
/usr/include/asm/system.h:246: error: parse error before `new'
/usr/include/asm/system.h: In function `long unsigned int __cmpxchg(...)':
/usr/include/asm/system.h:249: error: `size' undeclared (first use this
function)
/usr/include/asm/system.h:249: error: (Each undeclared identifier is reported
only once for each function it appears in.)
/usr/include/asm/system.h:253: error: parse error before `)' token
/usr/include/asm/system.h:259: error: parse error before `)' token
/usr/include/asm/system.h:265: error: parse error before `)' token
/usr/include/asm/system.h:269: error: `old' undeclared (first use this
function)
In file included from /usr/src/kernel-source-2.4.27/include/linux/module.h:13,
from hello.c:1:
/usr/src/kernel-source-2.4.27/include/linux/list.h: At global scope:
/usr/src/kernel-source-2.4.27/include/linux/list.h:37: error: parse error
before `new'
/usr/src/kernel-source-2.4.27/include/linux/list.h: In function `void
__list_add(...)':
/usr/src/kernel-source-2.4.27/include/linux/list.h:41: error: `next' undeclared
(first use this function)
/usr/src/kernel-source-2.4.27/include/linux/list.h:41: error: parse error
before `;' token
/usr/src/kernel-source-2.4.27/include/linux/list.h:44: error: `prev' undeclared
(first use this function)
/usr/src/kernel-source-2.4.27/include/linux/list.h:44: error: parse error
before `;' token
/usr/src/kernel-source-2.4.27/include/linux/list.h: At global scope:
/usr/src/kernel-source-2.4.27/include/linux/list.h:55: error: parse error
before `new'
/usr/src/kernel-source-2.4.27/include/linux/list.h: In function `void
list_add(...)':
/usr/src/kernel-source-2.4.27/include/linux/list.h:57: error: parse error
before `,' token
/usr/src/kernel-source-2.4.27/include/linux/list.h: At global scope:
/usr/src/kernel-source-2.4.27/include/linux/list.h:68: error: parse error
before `new'
/usr/src/kernel-source-2.4.27/include/linux/list.h: In function `void
list_add_tail(...)':
/usr/src/kernel-source-2.4.27/include/linux/list.h:70: error: parse error
before `,' token
/usr/src/kernel-source-2.4.27/include/linux/list.h: In function `void
list_del(list_head*)':
/usr/src/kernel-source-2.4.27/include/linux/list.h:94: error: invalid
conversion from `void*' to `list_head*'
/usr/src/kernel-source-2.4.27/include/linux/list.h:95: error: invalid
conversion from `void*' to `list_head*'
make: *** [hello.o] 错误 1
于是我把
INCLUDE=-I/usr/src/kernel-source-2.4.27/include/
改成:-I/usr/src/kernel-headers-2.4.27-2-386/include/和
-I/usr/src/kernel-headers-2.4.27-2/include/
都不行,为什么?
又下了 kernel-patch-debian-2.4.27 kernel-tree-2.4.27两个包,结果/usr/src下只有kernel-patch,后面的kernel-tree不知道那去了, debian下的内核源代码究竟是哪个啊?感觉好乱啊,不想redhat那么清晰!
求大虾们指点啊。。。
头像
yonsan
帖子: 887
注册时间: 2005-07-01 18:56
来自: 广州市
送出感谢: 0
接收感谢: 3 次

Re: 再问debian内核源码的问题!郁闷死了

#3

帖子 yonsan » 2005-09-06 18:40

emacsnw 写了:CC=gcc

NeptuneStar 写了:我在各位的指导下,下了kernel-source-2.4.27,kernel-headers-2.4.27-2-386
结果在/usr/src下有了kernel-source-2.4.27,kernel-headers-2.4.27-2,kernel- headers-2.4.27-2-386几个文件夹,为什么会有两个kernel-headers呢?后来我写了个简单的模块程序:
#include <linux/module.h>
int init_module(void)
{
printk("Hello,world!\n");
return 0;
}
void cleanup_module(void)
{
printk("Bye!\n");
}
它的makefile如下:
CC=g++
INCLUDE=-I/usr/src/kernel-source-2.4.27/include/
CFLAG=-D__KERNEL__ -DMODULE -Wall -O2 -g
hello.o:hello.c
$(CC) $(INCLUDE) $(CFLAG) -c hello.c

结果出了很多错:

g++ -I/usr/src/kernel-source-2.4.27/include/ -D__KERNEL__ -DMODULE -Wall -O2 -g -c hello.c
In file included from /usr/include/asm/system.h:5,
from /usr/src/kernel-source-2.4.27/include/linux/spinlock.h:6,
from /usr/src/kernel-source-2.4.27/include/linux/module.h:12,
from hello.c:1:
/usr/src/kernel-source-2.4.27/include/linux/kernel.h:75: error: type specifier
omitted for parameter `size_t'
/usr/src/kernel-source-2.4.27/include/linux/kernel.h:75: error: parse error
before `,' token
/usr/src/kernel-source-2.4.27/include/linux/kernel.h:77: error: type specifier
omitted for parameter `size_t'
/usr/src/kernel-source-2.4.27/include/linux/kernel.h:77: error: parse error
before `,' token
In file included from /usr/src/kernel-source-2.4.27/include/linux/spinlock.h:6,
from /usr/src/kernel-source-2.4.27/include/linux/module.h:12,
from hello.c:1:
/usr/include/asm/system.h:246: error: parse error before `new'
/usr/include/asm/system.h: In function `long unsigned int __cmpxchg(...)':
/usr/include/asm/system.h:249: error: `size' undeclared (first use this
function)
/usr/include/asm/system.h:249: error: (Each undeclared identifier is reported
only once for each function it appears in.)
/usr/include/asm/system.h:253: error: parse error before `)' token
/usr/include/asm/system.h:259: error: parse error before `)' token
/usr/include/asm/system.h:265: error: parse error before `)' token
/usr/include/asm/system.h:269: error: `old' undeclared (first use this
function)
In file included from /usr/src/kernel-source-2.4.27/include/linux/module.h:13,
from hello.c:1:
/usr/src/kernel-source-2.4.27/include/linux/list.h: At global scope:
/usr/src/kernel-source-2.4.27/include/linux/list.h:37: error: parse error
before `new'
/usr/src/kernel-source-2.4.27/include/linux/list.h: In function `void
__list_add(...)':
/usr/src/kernel-source-2.4.27/include/linux/list.h:41: error: `next' undeclared
(first use this function)
/usr/src/kernel-source-2.4.27/include/linux/list.h:41: error: parse error
before `;' token
/usr/src/kernel-source-2.4.27/include/linux/list.h:44: error: `prev' undeclared
(first use this function)
/usr/src/kernel-source-2.4.27/include/linux/list.h:44: error: parse error
before `;' token
/usr/src/kernel-source-2.4.27/include/linux/list.h: At global scope:
/usr/src/kernel-source-2.4.27/include/linux/list.h:55: error: parse error
before `new'
/usr/src/kernel-source-2.4.27/include/linux/list.h: In function `void
list_add(...)':
/usr/src/kernel-source-2.4.27/include/linux/list.h:57: error: parse error
before `,' token
/usr/src/kernel-source-2.4.27/include/linux/list.h: At global scope:
/usr/src/kernel-source-2.4.27/include/linux/list.h:68: error: parse error
before `new'
/usr/src/kernel-source-2.4.27/include/linux/list.h: In function `void
list_add_tail(...)':
/usr/src/kernel-source-2.4.27/include/linux/list.h:70: error: parse error
before `,' token
/usr/src/kernel-source-2.4.27/include/linux/list.h: In function `void
list_del(list_head*)':
/usr/src/kernel-source-2.4.27/include/linux/list.h:94: error: invalid
conversion from `void*' to `list_head*'
/usr/src/kernel-source-2.4.27/include/linux/list.h:95: error: invalid
conversion from `void*' to `list_head*'
make: *** [hello.o] 错误 1
于是我把
INCLUDE=-I/usr/src/kernel-source-2.4.27/include/
改成:-I/usr/src/kernel-headers-2.4.27-2-386/include/和
-I/usr/src/kernel-headers-2.4.27-2/include/
都不行,为什么?
又下了 kernel-patch-debian-2.4.27 kernel-tree-2.4.27两个包,结果/usr/src下只有kernel-patch,后面的kernel-tree不知道那去了, debian下的内核源代码究竟是哪个啊?感觉好乱啊,不想redhat那么清晰!
求大虾们指点啊。。。


真的将g++改为gcc就可以了? 你真的编译过这个示例吗? 如果你真的成功编译这个示例,能贴一下如何操作吗?
我将g++改为gcc并用了几个不同版本的内核头文件都还是出现以上一大堆编译出错!!(不是楼主的代码问题,在其它linux系统中编译可以通过)!
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
送出感谢: 0
接收感谢: 3 次
联系:

#4

帖子 leal » 2005-10-08 18:47

使用
INCLUDE=-I/usr/src/linux-headers-2.4.27-2-386/include/
应该就没问题了。
上次由 leal 在 2005-10-08 19:41,总共编辑 1 次。
用心×恒 | 豆瓣 | 门户 | Blog
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
送出感谢: 0
接收感谢: 3 次
联系:

#5

帖子 leal » 2005-10-08 18:48

或者#sudo apt-get install linux-headers-`uname -r`
安装自己所用内核的头文件。
用心×恒 | 豆瓣 | 门户 | Blog
yongyi
帖子: 3025
注册时间: 2005-05-07 23:57
送出感谢: 0
接收感谢: 0
联系:

#6

帖子 yongyi » 2005-10-08 19:15

顶一下,对此问题感兴趣。
独自看一看大海
总想起身边走在路上的朋友
Lenovo E290-420[Celeron-M420/256M/60G/Intel GMA950]
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
送出感谢: 0
接收感谢: 3 次
联系:

#7

帖子 leal » 2005-10-08 19:40

yongyi 写了:顶一下,对此问题感兴趣。


我在自己的系统上sudo apt-get install linux-headers-`uname -r`安装内核头文件后,用INCLUDE=-I/usr/src/linux-headers-2.6.10-5-386/include/进行编译,没有任何出错,可生成hello.o。相信针对2.4.27-2头文件,INCLUDE=-I/usr/src/linux-headers-2.4.27-2-386/include/也没问题。

用gcc编译。
用心×恒 | 豆瓣 | 门户 | Blog
zengsun
帖子: 334
注册时间: 2005-05-17 14:45
送出感谢: 0
接收感谢: 0
联系:

#8

帖子 zengsun » 2005-10-08 20:51

:( ,都没有看明白,自己试试先。
现在还是在学java!
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
送出感谢: 0
接收感谢: 3 次
联系:

#9

帖子 leal » 2005-10-08 21:14

http://www.linuxfans.org/nuke/modules.p ... c&t=114089
这儿有个2.6下的内核模块编译,2.6和2.4上内核模块编写有很大区别。
用心×恒 | 豆瓣 | 门户 | Blog
头像
yonsan
帖子: 887
注册时间: 2005-07-01 18:56
来自: 广州市
送出感谢: 0
接收感谢: 3 次

#10

帖子 yonsan » 2005-10-08 21:20

:o 是的, 2.6中有的头文件而2.4中不一定有。
I will be back!
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
送出感谢: 0
接收感谢: 3 次
联系:

#11

帖子 leal » 2005-10-08 21:32

不只是头文件,是外部内核模块的整个编写方法和代码布局有很大的不同。

所以我按7楼所列方法编译“成功”后,hello.o无法在2.6内核中运行。
用心×恒 | 豆瓣 | 门户 | Blog
star_s
帖子: 24
注册时间: 2006-10-11 19:09
送出感谢: 0
接收感谢: 0

#12

帖子 star_s » 2006-11-26 3:34

原来在ubuntu 下编译模快要加上INCLUDE=的,难怪我以前编译的时候也出现了一大堆的错误!
热爱开源……
回复

回到 “软件/网站开发”