Nejc Galof
Nejc Galof

Reputation: 2614

vfork() implicit declaration

I working in C with vfork(). My program working fine, but I have warning about implicit declaration.

My code:

if(vfork()==0){
...
}

My warning is:

implicit declaration of function 'vfork' [-Wimplicit-function-declaration] if(vfork()==0){^

I include those:

#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
#include <stdlib.h>

If I use fork() and not vfork() warning gone. Soo problem is only vfork() in my program. I don't know what this mean or how I fix that.

Upvotes: 0

Views: 1420

Answers (3)

gcpreston
gcpreston

Reputation: 19

Adding onto Igor's answer, make sure you aren't compiling for C99. clang gives me the error "implicit declaration of function 'vfork' is invalid in C99", and removing -std=c99 from the arguments fixed the issue.

Upvotes: 0

Igor Pejic
Igor Pejic

Reputation: 3698

You need to include these 2 headers:

#include <sys/types.h>
#include <unistd.h> 

Also, add this line in the beginning of the program:

#define _BSD_SOURCE 

Upvotes: 2

jmajnert
jmajnert

Reputation: 418

If you already have the required include files, then, depending on your system version, you may need to define some feature test macros. Please see documentation for your system (man vfork on unix-like systems)

Upvotes: 0

Related Questions