Linux 在 ubuntu 上编译 C 代码时遇到问题。(#include 错误)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19310541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Having trouble compiling C code on ubuntu. (#include errors)
提问by Dan Knott
I'm trying to compile a C program on the newest version of ubuntu, for the purpose of putting the compiled program on another machine later. However, when I compile with gcc prog.c -o prog, I get an error: "fatal error: asm/page.h: No such file or directory" Here are the headers:
我正在尝试在最新版本的 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>
I get an error at #include . It says fatal error: asm/page.h: No such file or directory. Like I said, I'm just looking to compile it. Is there a way for me to get the missing header or something? Thanks.
我在 #include 处收到错误消息。它说致命错误:asm/page.h:没有这样的文件或目录。就像我说的,我只是想编译它。有没有办法让我得到丢失的标题或什么?谢谢。
回答by mvp
Typically, asm/page.h
only exists in Linux kernel tree, normally under arch/<archname>/asm/page.h
, and should be used only be kernel code (or by kernel modules).
通常,asm/page.h
只存在于 Linux 内核树中,通常在 下arch/<archname>/asm/page.h
,并且应该只用于内核代码(或内核模块)。
stdio.h
and stdlib.h
, on other hand, are not to be used in kernel code.
So, your original source code looks fishy at best. Most likely it never needed that asm/page.h
in first place, and in reality it just needs something like linux/types.h
(this is one of headers included by one of kernel's asm/page.h
).
stdio.h
而stdlib.h
另一方面,不能在内核代码中使用。因此,您的原始源代码充其量看起来很可疑。很可能它一开始就不需要它asm/page.h
,实际上它只需要类似的东西linux/types.h
(这是一个内核包含的头文件之一asm/page.h
)。
回答by sandeep upadhyay
These header files are not missing they have been moved. The ubuntu packagers moved things around and the location of the header files that used to be in '/usr/include/asm' are now in '/usr/include/asm-generic '
这些头文件没有丢失,它们已被移动。ubuntu 打包器移动了一些东西,以前在 '/usr/include/asm' 中的头文件的位置现在在 '/usr/include/asm-generic '
To fix, just add a link:
要修复,只需添加一个链接:
sudo ln -s /usr/include/asm-generic /usr/include/asm
须藤 ln -s /usr/include/asm-generic /usr/include/asm
... or, maybe you are probably lacking build-essential. This is necessary to compile Code in linux . install build-essential
...或者,也许您可能缺乏必要的构建。这是在 linux 中编译代码所必需的。安装 build-essential
sudo apt-get install build-essential
sudo apt-get install build-essential
Now recreate the proper link:
现在重新创建正确的链接:
sudo ln -s /usr/include/asm-generic /usr/include/asm
须藤 ln -s /usr/include/asm-generic /usr/include/asm
Build-essential should install a /usr/include/asm-generic folder. If you lack such a folder reinstall build-essentials and verify the folder exists.
Build-essential 应该安装一个 /usr/include/asm-generic 文件夹。如果您缺少这样的文件夹,请重新安装 build-essentials 并验证该文件夹是否存在。
Does the /usr/include/asm-generic folder exist?
/usr/include/asm-generic 文件夹是否存在?
It is installed by build-essentials but examining it it is a dependency that installs it.
它由 build-essentials 安装,但检查它是安装它的依赖项。
if /usr/include/asm-generic does not exist, try to install or reinstall linux-libc-dev.
如果 /usr/include/asm-generic 不存在,请尝试安装或重新安装 linux-libc-dev。
That should create the asm-generic folder. If so delete that old link and relink asm to asm-generic.
这应该创建 asm-generic 文件夹。如果是这样,请删除该旧链接并将 asm 重新链接到 asm-generic。
回答by user3480038
Additionally you can add this to your make file
此外,您可以将其添加到您的 make 文件中
gcc -I /usr/include/x86_64-linux-gnu --your_other_arguments
gcc -I /usr/include/x86_64-linux-gnu --your_other_arguments