【问题标题】:CLONE_PTRACE not defined although sched.h is included尽管包含了 sched.h,但未定义 CLONE_PTRACE
【发布时间】:2012-03-15 19:16:22
【问题描述】:

Linux3.2.0

鉴于以下来源:

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

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

我明白了:

test.c:在函数“main”中: test.c:6:18: error: ‘CLONE_PTRACE’ undeclared (第一次在这个函数中使用)

为什么?

【问题讨论】:

    标签: c linux


    【解决方案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 
    

    【讨论】:

      猜你喜欢
      • 2015-07-11
      • 1970-01-01
      • 2020-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-14
      • 2023-04-02
      相关资源
      最近更新 更多