Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clone() function implicit declaration

Tags:

c

linux

clone

I am using the function clone() to create threads. The problem is that I am having this error during compilation:

implicit declaration of function ‘clone’ [-Wimplicit-function-declaration]

I included <linux/sched.h>. What can be the problem?

like image 309
user3242743 Avatar asked Aug 31 '26 01:08

user3242743


1 Answers

Add the following lines at the top of you source file

#define _GNU_SOURCE  
#include <linux/sched.h>        /* or #include <sched.h> */

_GNU_SOURCE is a Feature test macro.

Feature test macros allow the programmer to control the definitions that are exposed by system header files when a program is compiled. In order to be effective, a feature test macro must be defined before including any header files. This can be done either in the compilation command (cc -DMACRO=value) or by #define-ing the macro within the source code before #include-ing any headers.

  • Defining _GNU_SOURCE internally defines _USE_GNU.

  • sched.h included <bits/sched.h>

  • In <bits/sched.h>, the function clone() is declared ONLY if _USE_GNU is defined.

like image 174
TheCodeArtist Avatar answered Sep 03 '26 04:09

TheCodeArtist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!