Soham
Soham

Reputation: 873

Using List.h in C files, Ubuntu10.10

I am running Ubuntu 10.10 on an IBM R51 machine. When I access list.h to read it(manually/humanly) I open /usr/src/linux-headers-2.6.35-22/include/linux .

But when coding a C program in terminal, I cant invoke any #include because it is not in the default /usr/include folders.

When I change the statement to reflect the path by typing #include "/usr/src/linux-headers-2.6.35-22/include/linux/list.h" it returns errors as list.h in turn calls other header files which are mentioned as located in "linux" folder The header files are as you must be aware: "linux/poison.h", "linux/prefetch.h" and "asm/system.h"

So if I have to copy each, I can but prefetch in turn calls other dependencies, which are not present in /usr/include directory. I hope you understand.

How can I solve this problem?

Upvotes: 1

Views: 10933

Answers (3)

user611775
user611775

Reputation: 1353

  • adding -I/usr/src/linux is a no-go, since unsanitized header files are not meant to be used from user programs
  • you could manually copy list.h to your own project and sanitize
  • or use a library that is specifically for userspace and provides the same functionality (since you already used libHX elsewhere, you might want to continue reading into the linked list chapter)

Upvotes: 1

sarnold
sarnold

Reputation: 104080

The header files you are using are designed for internal use of the Linux kernel. They were not designed to be used by a userland program.

If you MUST use these headers (the Linux kernel list implementation is brilliant), copy the headers into your program source directory. Copy each file that is referenced, edit each one to remove whatever assumptions exist about being used in-kernel, and recurse until you're finished. I might suggest to make your own prefetch() macro that simply does nothing, rather than try to untangle <linux/prefetch.h>. Do the same for <linux/poison.h>, and untangle <linux/types> and <linux/stddef.h> (not too hard here :) as best you can.

And also be sure you license your project GPLv2 (and specifically GPLv2, the Linux kernel's COPYING file is quite strict that GPLv2 is the only license that applies; there is debate whether the GPL allows specifying only one version, but that is the license Linus chose ages ago, and the license that is valid on all files unless specified otherwise).

Upvotes: 1

David Victor
David Victor

Reputation: 827

Are you sure these headers are really what you need ? The standard C headers should be under /usr/include

Anyhow you need to pass the header search path to the compiler via the '-I' flag.

Pass the path via -I

-I/usr/src/linux-headers-2.6.35-22/include/linux

Then in your C code

#include "list.h"

Link to GCC manual & preprocessor directives

Upvotes: 1

Related Questions