我在/usr/src/linux-3.2/include/linux/unistd.h
linux内核中定义了一个结构:
#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_ */
在编译和安装内核,然后从它启动之后,我尝试编译并运行这个程序:
#include <stdio.h>
#include <linux/unistd.h>
int main(void) {
struct threadinfo_struct *ti = (struct threadinfo_struct*) malloc(sizeof(struct threadinfo_struct));
// ...
return 0;
}
但是,当我尝试这样做时,我在编译程序时遇到错误:
test.c: In function 'main':
test.c:4:78: error: invalid application of 'sizeof' to incomplete type 'struct threadinfo_struct'
为什么我会收到此错误,我该如何解决?鉴于我对 linux 内核非常陌生,这对我来说很难找到很多信息。