10

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:

#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.

1
  • What is your program intended to do? Why does it include all the above mess? Show much more of your source code, not only the #include directives! Commented Oct 11, 2013 at 5:29

3 Answers 3

6

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 '

To fix, just add a link:

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 . install build-essential

sudo apt-get install build-essential

Now recreate the proper link:

sudo 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.

Does the /usr/include/asm-generic folder exist?

It is installed by build-essentials but examining it it is a dependency that installs it.

if /usr/include/asm-generic does not exist, try to install or reinstall linux-libc-dev.

That should create the asm-generic folder. If so delete that old link and relink asm to asm-generic.

Sign up to request clarification or add additional context in comments.

2 Comments

Not only linking asm to asm-generic seems like really dirty hack, it is not likely to help anyway. On most recent Ubuntu 13.04, while directory /usr/include/asm-generic exists, page.h does not (and build-essential and linux-libc-dev are installed).
Okay, I installed build-essentials and created the link but I still receive the exact same error. /usr/include/asm-generic does exist, but it already existed before I installed build-essentials.
5

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).

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).

1 Comment

Actually the definitions which used to be in asm/page.h (like PAGE_SIZE) are in sys/user.h, not in linux/types.h.
0

Additionally you can add this to your make file

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

1 Comment

Here are some guidelines for How do I write a good answer?. This provided answer may be correct, but it could benefit from an explanation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.