我試圖熟悉kthreads並編寫了一個非常簡單的程序來測試它在C中的指導從:http://tuxthink.blogspot.com/2011/02/kernel-thread-creation-1.html。我在MacOSX上的VMware上運行Ubuntu。致命錯誤:linux/kthread.h:沒有這樣的文件或目錄編譯終止
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "cycle.h"
#include <linux/kthread.h>
#include <linux/sched.h>
int main(){
static struct task_struct *kthread;
thread1 = kthread_create(thread_fn, NULL, "thread1");
wake_up_process(thread1);
kthread_stop(thread1);
return 0;
}
當我嘗試編譯此使用gcc(GCC test5.c -o test5.out)我得到「致命錯誤:LINUX/kthread.h:沒有這樣的文件或目錄彙編終止」
當我在/ usr/include/linux /中查找沒有kthread.h文件時,所以它看起來很合理。當我搜索kthread.hi時,在/usr/src/linux-headers-3.2.0-31/include/linux中找到一個,在/usr/src/linux-headers-3.2.0-29/include/linux中找到一個,但是我只是不斷收到錯誤消息後,我試圖複製其中一個到/ usr /在include/linux /:
In file included from /usr/include/linux/kthread.h:4:0,
from test5.c:5:
/usr/include/linux/err.h:22:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ERR_PTR’
/usr/include/linux/err.h:27:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PTR_ERR’
/usr/include/linux/err.h:32:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘IS_ERR’
/usr/include/linux/err.h:37:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘IS_ERR_OR_NULL’
/usr/include/linux/err.h:49:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ERR_CAST’
/usr/include/linux/err.h:55:32: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PTR_RET’
In file included from test5.c:5:0:
/usr/include/linux/kthread.h:7:10: error: expected declaration specifiers or ‘...’ before numeric constant
/usr/include/linux/kthread.h:7:13: error: expected declaration specifiers or ‘...’ before numeric constant
/usr/include/linux/kthread.h:58:2: error: unknown type name ‘spinlock_t’
/usr/include/linux/kthread.h:59:19: error: field ‘work_list’ has incomplete type
/usr/include/linux/kthread.h:64:19: error: field ‘node’ has incomplete type
/usr/include/linux/kthread.h:66:2: error: unknown type name ‘wait_queue_head_t’
/usr/include/linux/kthread.h:67:2: error: unknown type name ‘atomic_t’
/usr/include/linux/kthread.h:128:1: error: unknown type name ‘bool’
test5.c: In function ‘main’:
test5.c:11:2: error: ‘thread1’ undeclared (first use in this function)
test5.c:11:2: note: each undeclared identifier is reported only once for each function it appears in
test5.c:11:12: error: ‘thread_fn’ undeclared (first use in this function)
如何解決這個任何想法將是非常非常感謝!
'sudo apt-get install linux-headers'或者一個類似名字的包 – 2012-10-29 20:55:39
@ H2CO3我不認爲這會解決問題,因爲我認爲這是用戶空間代碼。 – iabdalkader