How to Fix the Implicitly Declaring Library Function Warning in C
In the process of compiling a C program, you may encounter a warning issued by the compiler that looks like this:
1 | hello.c:6:3: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration] |
or
1 | hello.c:5:16: warning: implicitly declaring library function 'strlen' with type 'unsigned long (const char *)' [-Wimplicit-function-declaration] |
This warning arises because you have used a function from the standard library without including the appropriate header file.
Fortunately, the compiler provides a helpful suggestion:
1 | hello.c:5:16: note: include the header <string.h> or explicitly provide a declaration for 'strlen' |
This pointer guides you in the right direction.
To resolve this issue, simply add the following line at the top of your C file:
1 |
This inclusion will rectify the problem and enable successful compilation.