我已经安装了Fedora 22,它有默认内核4.0.4。但是我需要内核4.1.4,所以我在Fedora 22上安装了内核4.1.4。并在grub中为新内核创建一个条目。
内核4.1.4安装成功,我可以使用新内核登录。
"uname -a“的输出
uname -a
Linux localhost.localdomain 4.1.4 #1 SMP Fri Aug 7 10:52:36 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux新内核之路-
/usr/src/linux-4.1.4包含文件夹的路径
/usr/src/linux-4.1.4/include现在我编写了一个C程序,它使用宏AF_MPLS,它是在新的内核头中定义的。C程序编译失败,因为AF_MPLS不在/usr/include/sys/socket.h中。
发现错误-
RouteMPLS.c: In function âroute_addâ:
RouteMPLS.c:212:24: error: âAF_MPLSâ undeclared (first use in this function)
req.r.rtm_family = AF_MPLS;RouteMPLS.c中使用的头文件
#include <stdio.h>
#include <asm/types.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <errno.h>因此,我将头文件a/c的位置更改为新内核-
#include "/usr/src/linux-4.1.4/include/linux/socket.h"它仍然抛出一个编译错误,然后我尝试使用
gcc RouteMPLS.c -I /usr/src/linux-4.1.4/include/
In file included from /usr/src/linux-4.1.4/include/linux/kernel.h:6:0,
from /usr/src/linux-4.1.4/include/linux/skbuff.h:17,
from /usr/src/linux-4.1.4/include/linux/netlink.h:6,
from RouteMPLS.c:3:
/usr/src/linux-4.1.4/include/linux/linkage.h:7:25: fatal error: asm/linkage.h: No such file or directory编译已终止。
请指导我如何使用新的内核头安装我们的c程序-
默认内核头位置-
/usr/include新的内核头位置-
/usr/src/linux-4.1.4/include提前谢谢。
发布于 2015-08-10 21:43:07
问题是,linux内核4.1.4头文件位于目录中,用于内核编译。
要编译用户程序,编译器通常在/usr/include中查找它们(好吧,在新的体系结构中,这要复杂一些),并且通常会有安装在/usr/include中的运行内核的内核头的副本
但是现在,您有一个内核头版本不匹配。您没有说明从哪里下载了这些源代码,但是在内核源代码树的Documentation子目录中,您有一些文档解释了如何在适当的位置安装内核头,因此系统应用程序的编译器会发现它们是正确的。
阅读/usr/src/linux-4.1.4/Documentation上的文档以获得一个文件,该文件解释了如何在适当的位置安装内核头。主要是指安装在/usr/include/linux、/usr/include/asm和(如您的情况) /usr/include/asm-amd64下的所有文件。
注意:
在内核源代码树中进行了一些搜索之后,我在Makefile中找到了一个目标headers_install (通过尝试make help),我认为可以将头文件从内核树安装到适当的位置。
因此,安装内核头文件的最可能的方法是:
make headers_install或者(万一你必须把它们安装在其他地方)
INSTALL_HDR_PATH=<new_path> make headers_install(默认情况下,安装将转到./usr)
https://stackoverflow.com/questions/31913435
复制相似问题