新内核编译问题

Compilation issue on new kernel

我安装了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

提前致谢。

问题是您在内核编译目录中有 linux 内核 4.1.4 头文件。

为了编译用户程序,编译器通常会在 /usr/include 中寻找它们(好吧,在新的架构中,它会更复杂一些)并且通常会有 [=41] 的内核头文件的副本=]内核里面安装/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