Dan Knott
Dan Knott

Reputation: 137

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

Upvotes: 10

Views: 37906

Answers (3)

Nilufar Makhmudova
Nilufar Makhmudova

Reputation: 201

Additionally you can add this to your make file

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

Upvotes: 0

sandeep upadhyay
sandeep upadhyay

Reputation: 147

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.

Upvotes: 6

mvp
mvp

Reputation: 116048

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

Upvotes: 5

Related Questions