如何获取内核头文件?
我试图在内核 2.6.21 中进行新的系统调用
,其中一个新的系统调用使用“sys_write”函数,
但是要使用此函数,我意识到我必须根据 2.6.21 版本安装内核头文件。
但我找不到内核头文件(2.6.21)
我尝试了 apt-get install linux-headers-'uname -r' , apt-cache search linux-headers-$( uname -r)
但我找不到任何东西..
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/syscalls.h>
#include <linux/fcntl.h>
#include <asm/uaccess.h>
int main(){
int fd;
int old_fs;
old_fs = get_fs();
set_fs(KERNEL_DS);
fd = sys_open("config.txt", O_RDONLY, 0);
if(fd >= 0)
sys_close(fd);
set_fs(old_fs);
return 0;
}
vv.c:2:24: error: linux/init.h: No such file or directory
vv.c:3:26: error: linux/module.h: No such file or directory
vv.c:4:28: error: linux/syscalls.h: No such file or directory
In file included from /usr/include/asm/fcntl.h:1,
from /usr/include/linux/fcntl.h:4,
from vv.c:5:
/usr/include/asm-generic/fcntl.h:120: error: expected specifier-qualifier-list before ‘off_t’
/usr/include/asm-generic/fcntl.h:143: error: expected specifier-qualifier-list before ‘loff_t’
vv.c:6:25: error: asm/uaccess.h: No such file or directory
vv.c: In function ‘main’:
vv.c:12: error: ‘KERNEL_DS’ undeclared (first use in this function)
vv.c:12: error: (Each undeclared identifier is reported only once
vv.c:12: error: for each function it appears in.)
另外,上面的头文件就是我想要的。
如何获取内核头文件?
请帮我..
i'm trying to make new system calls in kernel 2.6.21
and one of the new system calls use 'sys_write' function,
but to use this function, i realized that i must install kernel header file according to 2.6.21 version.
but i can't find kernel header file(2.6.21)
i tried apt-get install linux-headers-'uname -r'
, apt-cache search linux-headers-$(uname -r)
but i can't find anything..
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/syscalls.h>
#include <linux/fcntl.h>
#include <asm/uaccess.h>
int main(){
int fd;
int old_fs;
old_fs = get_fs();
set_fs(KERNEL_DS);
fd = sys_open("config.txt", O_RDONLY, 0);
if(fd >= 0)
sys_close(fd);
set_fs(old_fs);
return 0;
}
vv.c:2:24: error: linux/init.h: No such file or directory
vv.c:3:26: error: linux/module.h: No such file or directory
vv.c:4:28: error: linux/syscalls.h: No such file or directory
In file included from /usr/include/asm/fcntl.h:1,
from /usr/include/linux/fcntl.h:4,
from vv.c:5:
/usr/include/asm-generic/fcntl.h:120: error: expected specifier-qualifier-list before ‘off_t’
/usr/include/asm-generic/fcntl.h:143: error: expected specifier-qualifier-list before ‘loff_t’
vv.c:6:25: error: asm/uaccess.h: No such file or directory
vv.c: In function ‘main’:
vv.c:12: error: ‘KERNEL_DS’ undeclared (first use in this function)
vv.c:12: error: (Each undeclared identifier is reported only once
vv.c:12: error: for each function it appears in.)
additionally, above header files is what i want to.
how can i get the kernel header file?
please help me..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标头安装完成了吗?如果是这样,那么它们应该安装在
/usr/include
中,并且您给出的包含指令应该可以正常工作。编辑:
首先运行:
sudo apt-get update
要确保您拥有最新的软件包,然后:
sudo apt-get install linux-headers-$(uname -r)
这是一个包含 Ubuntu 中所有内核头文件的包。
Did installing the headers complete? If so then they should be installed in
/usr/include
and the include directives you gave should just work.Edit:
First run:
sudo apt-get update
To make sure you have the latest packages, then:
sudo apt-get install linux-headers-$(uname -r)
This is the one package that should contain all the kernel header files in Ubuntu.