Implicit declaration of function ‘wait’
76,986
Solution 1
You are probably missing the headers for wait(2)
:
#include <sys/types.h>
#include <sys/wait.h>
Solution 2
You need to put:
#include <sys/types.h>
#include <sys/wait.h>
at the top of the program to get the declaration of the function.
This is shown in the man page
Related videos on Youtube
Author by
AyeJay
Updated on May 03, 2020Comments
-
AyeJay about 4 years
I am getting a warning > Implicit declaration of function ‘wait’ < and when I run the program it works correctly, I would like to understand why I am getting this warning?
Thanks in advance
Edit: I forgot to add the library included
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> void create (char* program, char** arg_list) { /* put your code here */ pid_t childPid; int status; if((childPid = fork()) < 0){ printf("Failed to fork() --- exiting...\n"); exit(1); } else if (childPid == 0){ // --- inside the child process if(execvp(program, arg_list) < 0){ // Failed to run the command printf("*** Failed to exec %s\n", program); exit(1); } } else{ // --- parent process while(wait(&status) != childPid) printf("...\n"); } }
-
Barmar over 7 yearsYou're missing the
#include
line for the function.
-
-
AyeJay over 7 yearsThank you, I forgot the wait library
-
MichaelM about 2 yearsIs
sys/types.h
necessary if you aren't utilizing any of the types returned from await
function call? -
P.P about 2 years@MichaelM I answered based on what the Linux man page had at that time .But it was removed since in this commit. The reason it was included earlier was due to types used by
wait
(such aspid_t
). [continued] -
P.P about 2 years@MichaelM But including necessary types should be handled by
sys/wait.h
itself rather than requiring users to include them. POSIX doesn't requiresys/types.h
either. In summary,sys/types.h
isn't required for usingwait
! -
MichaelM about 2 years@P.P thanks for the clarification! I just wanted to make sure I was understanding correctly. I was able to compile without
sys/types.h
and didn't run into any complications, but I wanted to ensure there were no "hidden" issues I wasn't aware of.