2
我已經在Linux內核中的/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_ */
編譯和安裝內核,然後從它啓動後,我嘗試編譯並運行此程序:
test.c: In function 'main':
test.c:4:78: error: invalid application of 'sizeof' to incomplete type 'struct threadinfo_struct'
:
#include <stdio.h>
#include <linux/unistd.h>
int main(void) {
struct threadinfo_struct *ti = (struct threadinfo_struct*) malloc(sizeof(struct threadinfo_struct));
// ...
return 0;
}
然而,當我試圖做到這一點,我在程序編譯得到一個錯誤
爲什麼我得到這個錯誤,我該如何解決?鑑於我對linux內核非常陌生,所以我很難找到很多信息。
謝謝,這工作得很好! :d – Darthfett