Skip to content

How to solve the implicitly declaring library function warning in C

Learn how to solve the implicitly declaring library function warning in C

When compiling a C program you might find that the compiler gives you a warning similar to

hello.c:6:3: warning: implicitly declaring library function
      'printf' with type 'int (const char *, ...)'
      [-Wimplicit-function-declaration]
  printf("Name length: %u", length);
  ^

or

hello.c:5:16: warning: implicitly declaring library function
      'strlen' with type 'unsigned long (const char *)'
      [-Wimplicit-function-declaration]
  int length = strlen(name);
               ^

This problem occurs because you used a function from the standard library without first including the appropriate header file.

The compiler will also give you a suggestion, like the following one:

hello.c:5:16: note: include the header <string.h> or
      explicitly provide a declaration for 'strlen'

which points you in the right direction.

In this case, adding

#include <stdio.h>

at the top of the C file will solve the issue.


→ Get my C Handbook

→ I wrote 17 books to help you become a better developer:

  • C Handbook
  • Command Line Handbook
  • CSS Handbook
  • Express Handbook
  • Git Cheat Sheet
  • Go Handbook
  • HTML Handbook
  • JS Handbook
  • Laravel Handbook
  • Next.js Handbook
  • Node.js Handbook
  • PHP Handbook
  • Python Handbook
  • React Handbook
  • SQL Handbook
  • Svelte Handbook
  • Swift Handbook
...download them all now!

Also, JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025

Bootcamp 2025

Join the waiting list