9

我正在尝试在最新版本的 ubuntu 上编译一个 C 程序,以便稍后将编译后的程序放在另一台机器上。但是,当我使用 gcc prog.c -o prog 编译时,出现错误:“致命错误:asm/page.h:没有这样的文件或目录” 以下是标题:

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <limits.h>
#include <signal.h>
#include <unistd.h>
#include <sys/uio.h>
#include <sys/mman.h>
#include <asm/page.h>
#include <asm/unistd.h>

我在 #include 收到错误。它说致命错误:asm/page.h:没有这样的文件或目录。就像我说的,我只是想编译它。有没有办法让我得到丢失的标题或其他东西?谢谢。

4

3 回答 3

5

通常,asm/page.h仅存在于 Linux 内核树中,通常在 下arch/<archname>/asm/page.h,并且只能用于内核代码(或内核模块)。

stdio.hstdlib.h另一方面,不能在内核代码中使用。因此,您的原始源代码充其量看起来很可疑。很可能它asm/page.h一开始就不需要它,实际上它只需要类似的东西linux/types.h(这是内核之一包含的头文件之一asm/page.h)。

于 2013-10-11T05:15:33.283 回答
5

这些头文件没有丢失,它们已被移动。ubuntu 打包程序移动了一些东西,以前在“/usr/include/asm”中的头文件的位置现在在“/usr/include/asm-generic”中

要修复,只需添加一个链接:

sudo ln -s /usr/include/asm-generic /usr/include/asm

...或者,也许您可​​能缺乏构建必需品。这是在 linux 中编译代码所必需的。安装构建必备

sudo apt-get install build-essential

现在重新创建正确的链接:

sudo ln -s /usr/include/asm-generic /usr/include/asm

Build-essential 应该安装一个 /usr/include/asm-generic 文件夹。如果您缺少这样的文件夹,请重新安装 build-essentials 并验证该文件夹是否存在。

/usr/include/asm-generic 文件夹是否存在?

它由 build-essentials 安装,但检查它是安装它的依赖项。

如果 /usr/include/asm-generic 不存在,请尝试安装或重新安装 linux-libc-dev。

那应该创建 asm-generic 文件夹。如果是这样,请删除该旧链接并将 asm 重新链接到 asm-generic。

于 2013-10-11T06:09:22.407 回答
0

此外,您可以将其添加到您的 make 文件中

gcc -I /usr/include/x86_64-linux-gnu --your_other_arguments

于 2019-09-13T15:11:28.910 回答