tags:

views:

9924

answers:

2

I'm getting a number of these warnings when compiling a few binaries:

warning: incompatible implicit declaration of built-in function ‘strcpy’
warning: incompatible implicit declaration of built-in function ‘strlen’
warning: incompatible implicit declaration of built-in function ‘exit’

To try to resolve this, I have added

#include <stdlib.h>

at the top of the C files associated with this warning, in addition to compiling with the following flags:

CFLAGS = -fno-builtin-exit -fno-builtin-strcat -fno-builtin-strncat -fno-builtin-strcpy -fno-builtin-strlen -fno-builtin-calloc

I am using GCC 4.1.2:

$ gcc --version
gcc (GCC) 4.1.2 20080704

What should I do to resolve these warnings? Thanks for your advice.

+17  A: 

In C, using a previously undeclared function constitutes an implicit declaration of the function. In an implicit declaration, the return type is int if I recall correctly. Now, GCC has built-in definitions for some standard functions. If an implicit declaration does not match the built-in definition, you get this warning.

To fix the problem, you have to declare the functions before using them; normally you do this by including the appropriate header. I recommend not to use the -fno-builtin-* flags if possible.

Instead of stdlib.h, you should try

#include <string.h>

That's where strcpy and strncpy are defined, at least according to the strcpy(2) man page.

The exit function is defined in stdlib.h, though, so I don't know what's going on there.

Ville Laurikari
Thanks, I have about 20 .c files to clean up and missed adding some headers.
Alex Reynolds
hi#include <string.h>#include <stdlib.h>
ambika
A: 

I have somewhat the same problem. I have declared both #include <dirent.h> and #include <strings.h> but I get the error from gywin 1.7

imcompatible implicit declaration of built-in function 'strcat'
imcompatible implicit declaration of built-in function 'strcpy'
imcompatible implicit declaration of built-in function 'memset'

May I know what can I do to fix this?

linuxmod
I cleaned up your format. I don't know what `dirent.h` is, but it's not standard C90. I don't know what `strings.h` is either, although it's very similar to a standard header. Try `string.h` instead.
David Thornley