This error message is because sleep
the function , but unistd.h
the header file is not included, so the compiler cannot recognize the declaration of sleep
the function .
sleep
function is a standard library function used to cause the program to pause for a period of time. Its declaration is in the unistd.h
header file. Therefore, if you want to use sleep
the function , you need to include unistd.h
the header file in your code. For example:
#include <unistd.h>
int main() {
sleep(1);
return 0;
}
In this example, we include unistd.h
the header so we can use sleep
the function.
It should be noted that if -Werror
the option , the compiler will treat all warnings as errors, resulting in compilation failure. If you don't want this warning to be an error, you can use -Wno-error=implicit-function-declaration
the option to disable this warning. For example:
gcc -o program program.c -Wno-error=implicit-function-declaration
In this way, compilation will not fail even if implicit declaration of function ‘sleep’
there warnings.