2012-02-25 68 views
1

Linux3.2.0CLONE_PTRACE雖然sched.h中包含

鑑於以下來源:

#include <stdio.h> 
#include <sched.h> 

int main(void) 
{ 
     printf("%i \n", CLONE_PTRACE); 
     return 0; 
} 

我得到:

test.c的:在函數 '主': 測試.c:6:18:錯誤:'CLONE_PTRACE'未申報(首次在此功能中使用)

爲什麼?

回答

1

你需要用#define _GNU_SOURCE這樣或那樣的方式來獲得這些常量。 (見clone(2)手冊頁。)

並另存爲t.c代碼:

$ gcc -std=c99 t.c 
t.c: In function ‘main’: 
t.c:6:25: error: ‘CLONE_PTRACE’ undeclared (first use in this function) 
t.c:6:25: note: each undeclared identifier is reported only once for each function it appears in 
$ gcc -std=c99 -D_GNU_SOURCE t.c 
$ ./a.out 
8192 
+0

謝謝,這解決了我的問題。 – 2012-02-25 17:06:02