0

I'm trying to compile a program with this gcc command:

gcc -c -fomit-frame-pointer -O2 sth.c

These header files are included:

#include <linux/kernel.h>    //line 1
#include <linux/module.h>    //line 2
#include <sys/syscall.h>     //line 3
#include <linux/proc_fs.h>   //line 4
#include <linux/types.h>     //line 5
#include <linux/dirent.h>    //line 6
#include <asm/unistd.h>      //line 7

I get "no such file or directory" error for line 2,4 and 6 though they are located in /usr/src/kernels/3.10.14-100.fc18.x86_64/include/linux/ just as the other 4.

I've compiled some other programs whitch include kernel header files on this system before (using Makefiles) (fedora 18) before and I'm sure for example it didn't get such error for dirent.h or proc_fs.h. I think maybe I should use some other options with gcc that maybe was considered in those Makefiles!

kernel-headerfiles and kernel-devel package of the same version of my running kernel is installed.

4
  • It's nice of you to tell us the problematic line numbers, but how are we supposed to know what these lines contain? Commented Oct 13, 2013 at 12:31
  • Please Stop Writing Like This. It's horrible to read. Commented Oct 13, 2013 at 12:32
  • @ ugoren @ Smax Smaxović : Sorry.I hope now it's more readble. Commented Oct 13, 2013 at 12:48
  • possible duplicate of Having trouble compiling C code on ubuntu. (#include errors) Commented Oct 13, 2013 at 13:23

1 Answer 1

2

The userspace kernel headers are located in /usr/include/linux, not in /usr/src/.... The latter path contains headers intended for kernel modules, not userspace programs.

If the program is question is actually a kernel module, then you need to use KBuild in order to compile it, since kernel modules need a special build environment. See: Understand what is KBuild

Also take a look at:

/usr/src/linux/Documentation/kbuild/modules.txt
Sign up to request clarification or add additional context in comments.

2 Comments

@ Nikos C.:This program is a kernel module. Sorry that I didn't mention, I've not noticed this.
@Mjina Kernel modules can't be compiled like normal programs. Use KBuild to get a kernel build environment. I updated the answer.

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.