Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 536
Dan Knott Avatar asked Oct 11 '13 05:10

Dan Knott


2 Answers

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

like image 110
mvp Avatar answered Oct 22 '22 08:10

mvp


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.

like image 44
sandeep upadhyay Avatar answered Oct 22 '22 07:10

sandeep upadhyay