我正在使用函数 clone()
创建线程。问题是我在编译期间遇到此错误:
implicit declaration of function ‘clone’ [-Wimplicit-function-declaration]
我包括了 <linux/sched.h>
.可能是什么问题?
最佳答案
在源文件的顶部添加以下行
#define _GNU_SOURCE
#include <linux/sched.h> /* or #include <sched.h> */
_GNU_SOURCE
是一个功能测试宏。
功能测试宏允许程序员在编译程序时控制系统头文件公开的定义。为了有效,必须在包含任何头文件之前定义功能测试宏。这可以在编译命令 ( cc -DMACRO=value
) 或 #define
中完成。 -ing #include
之前源代码中的宏-ing 任何 header 。
关于clone() 函数隐式声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23579354/