【问题标题】:CLONE_VM undeclared (first use in this function)CLONE_VM 未声明(在此函数中首次使用)
【发布时间】:2014-04-22 08:40:52
【问题描述】:

我正在使用 linux c 中的克隆功能。

但是,当我尝试编译我的代码时,我遇到了错误 CLONE_VM undeclared (first use in this function)。

我去谷歌寻求解决方案,其中一个网站提到#include <sched.h> 必须包含在代码中。我已经在我的代码中包含了#include <sched.h>,但编译错误仍然存​​在。

有什么帮助吗? :)

int c = clone(child,p+STACKSIZE-1,CLONE_VM|SIGCHLD,NULL) ;

【问题讨论】:

  • 不要使用clone。使用标准的 pthread 库。 clone 系统调用主要用于 Posix 线程的实现者。

标签: c linux clone


【解决方案1】:

将以下行添加到代码的开头

   #define _GNU_SOURCE             /* See feature_test_macros(7) */
   #include <sched.h>

您可以找出需要哪些头文件和/或宏

  • man 2 syscall_name
  • man 3 library_function_name

顺便说一句,_GNU_SOURCE 的含义等可以通过man 7 feature_test_macros 了解。

【讨论】:

  • 谢谢!有效!我可以知道 _GNU_SOURCE 是做什么的吗?
  • 没关系。我在这里找到了答案。 stackoverflow.com/questions/5582211/…
  • @LawrenceWong 你可以通过man 7 feature_test_macros找到它
【解决方案2】:

有时包括#include &lt;sched.h&gt; 将不起作用,因此请从 linux 指向 sched.h 文件。即#include &lt;linux/sched.h&gt;

【讨论】:

  • 对我来说,当我将“#define _GNU_SOURCE”然后“#include ”放在源代码的 top 上时(在所有其他#includes 之上) .
猜你喜欢
  • 2012-05-19
  • 2012-05-07
  • 2012-07-13
  • 2013-05-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多