[英]Having trouble compiling C code on ubuntu. (#include errors)
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. 我正在尝试在最新版本的ubuntu上编译一个C程序,以便稍后将编译好的程序放在另一台机器上。 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: 但是,当我使用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 . 我在#include时收到错误。 It says fatal error: asm/page.h: No such file or directory. 它说致命错误:asm / page.h:没有这样的文件或目录。 Like I said, I'm just looking to compile it. 就像我说的,我只是想编译它。 Is there a way for me to get the missing header or something? 有没有办法让我得到丢失的标题或什么? Thanks. 谢谢。
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. 另一方面, stdio.h
和stdlib.h
不能在内核代码中使用。 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
). 很可能它首先从不需要asm/page.h
,实际上它只需要像linux/types.h
这样的东西(这是内核的一个asm/page.h
包含的头文件之一)。
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 sudo 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 . 这是在linux中编译Code所必需的。 install build-essential 安装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 sudo ln -s / usr / include / asm-generic / usr / include / asm
Build-essential should install a /usr/include/asm-generic folder. Build-essential应该安装/ usr / include / asm-generic文件夹。 If you lack such a folder reinstall build-essentials and verify the folder exists. 如果您缺少此类文件夹,请重新安装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. 那应该创建asm-generic文件夹。 If so delete that old link and relink asm to asm-generic. 如果是这样,请删除旧链接并将asm重新链接到asm-generic。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.