Pages

Wednesday, June 8, 2011

gcc: Compilation Warning: incompatible implicit declaration of built-in function `exit’

reference: ttp://joysofprogramming.com/gcc-incompatible-implicit-declaration-exit/

Posted by Joys of Programming on in C/C++


The purpose of exit() as described by the man page
exit - cause normal process termination
Let’s make use of exit in a simple program
int main(int argc, char*argv[]){
    int status;
exit(status);
    return 0;
}
Now compile the program exit.c…
$ gcc exit.c

You will see the following warnings.
exit.c: In function ‘main’:
exit.c:4: warning: incompatible implicit declaration of built-in function ‘exit’
This is because we missed to add the headers which declare the function exit() and the supporting types
Let’s add the relevant header files (.h) and compile the program
#include <stdlib.h>
int main(int argc, char*argv[]){
    int status;
exit(status);
    return 0;
}
Compile..
$ gcc exit.c
Now you will find that the program is successfully compiled and linked.

No comments:

Post a Comment