Reputation: 7955
I have a structure defined in /usr/src/linux-3.2/include/linux/unistd.h
of the linux kernel:
#ifndef _LINUX_UNISTD_H_
#define _LINUX_UNISTD_H_
struct threadinfo_struct {
int pid;
int nthreads;
int *tid;
};
/*
* Include machine specific syscall numbers
*/
#include <asm/unistd.h>
#endif /* _LINUX_UNISTD_H_ */
After compiling and installing the kernel, then booting from it, I try to compile and run this program:
#include <stdio.h>
#include <linux/unistd.h>
int main(void) {
struct threadinfo_struct *ti = (struct threadinfo_struct*) malloc(sizeof(struct threadinfo_struct));
// ...
return 0;
}
However, when I try and do this, I get an error in compilation of the program:
test.c: In function 'main':
test.c:4:78: error: invalid application of 'sizeof' to incomplete type 'struct threadinfo_struct'
Why am I getting this error, and how can I resolve it? This is difficult for me to find much information, given that I am very new to the linux kernel.
Upvotes: 2
Views: 644
Reputation: 6095
The file /usr/src/linux-3.2/include/linux/unistd.h
is not on a standard include path.
The user-space applications have their own build environment. You are including the file that is located at /usr/include/linux/unistd.h
. Most of the internal kernel structures are not defined for user-space applications.
If you really need this structure to be defined then you need to copy the file from the linux tree to your project directory, or adjust the gcc command by adding the -isystem/usr/src/linux-3.2/include/
option.
However, the latter will create a big mess, so better just copy the file.
Upvotes: 1