更新Linux内核头文件(linux headers)
三 8th, 2013
2,474 views | 发表评论 | Trackback
一般来说,如果不是自己编译kernel,那么更新头文件是比较容易的事情,在Ubuntu/Fedora等操作系统上,可以直接安装相应的linux-headers软件包,下面就演示了在Ubuntu上安装内核头文件的过程。
View Code BASH
1
2
3
4
5
6
7
8
9
master@jay-intel:~/workspace/c-study$ uname -r
3.2.0-33-generic
master@jay-intel:~/workspace/c-study$ apt-get install linux-headers-$(uname -r)
Reading Done
Building dependency tree
Reading Done
linux-headers-3.2.0-33-generic is already the newest version.
linux-headers-3.2.0-33-generic set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 331 not upgraded.
然而,如果自己编译Linux kernel并用它启动了系统,然后为了让本地程序基于当前kernel的headers来编译,就需要自己手动更新内核的头文件了。手动更新linux headers的步骤如下:
1. 在Linux kernel目录中,执行“make headers_install”命令,将headers安装到当前目录的usr/include/下面。
2. 将以前的headers备份:包括/usr/include/目录下的asm,asm-generic,linux等目录。
3. 将刚才生成的当前编译内核目录下的usr/include/中的asm,asm-generic,linux等目录复制到/usr/include/目录下即可。
(当然如果还需要更新其他的目录的头文件,也都可以一起复制过去。)

操作演示如下:
View Code BASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[root@jay-linux kvm.git]# make headers_install
  CHK    include/generated/uapi/linux/version.h
  WRAP    arch/x86/include/generated/asm/clkdev.h
  SYSHDR  arch/x86/syscalls/../include/generated/uapi/asm/unistd_32.h
  SYSHDR  arch/x86/syscalls/../include/generated/uapi/asm/unistd_64.h
  SYSHDR  arch/x86/syscalls/../include/generated/uapi/asm/unistd_x32.h
  SYSTBL  arch/x86/syscalls/../include/generated/asm/syscalls_32.h
  SYSHDR  arch/x86/syscalls/../include/generated/asm/unistd_32_ia32.h
  SYSHDR  arch/x86/syscalls/../include/generated/asm/unistd_64_x32.h
  SYSTBL  arch/x86/syscalls/../include/generated/asm/syscalls_64.h
  HOSTCC  arch/x86/tools/relocs
  HOSTCC  scripts/unifdef
  INSTALL include/asm-generic (35 files)
  INSTALL include/drm (15 files)
  INSTALL include/linux/byteorder (2 files)
  INSTALL include/linux/caif (2 files)
  INSTALL include/linux/can (5 files)
  INSTALL include/linux/dvb (8 files)
  INSTALL include/linux/hdlc (1 file)
  INSTALL include/linux/hsi (1 file)
  INSTALL include/linuxlinux内核文件放在哪/isdn (1 file)
  <省略部分信息...>
  INSTALL include/asm (64 files)
 
[root@jay-linux include]# pwd
/usr/include
[root@jay-linux include]# mv asm asm_orig
[root@jay-linux include]# mv linux linux_orig
[root@jay-linux include]# mv asm-generic asm-generic_orig
 
[root@jay-linux kvm.git]# pwd
/root/kvm_demo/kvm.git
[root@jay-linux kvm.git]# cp -r usr/include/asm /usr/include/
[root@jay-linux kvm.git]# cp -r usr/include/asm-generic/ /usr/include/
[root@jay-linux kvm.git]# cp -r usr/include/linux /usr/include/

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。